~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
690
690
        """
691
691
        class_run = self.run
692
692
        def run(*args, **kwargs):
 
693
            for hook in Command.hooks['pre_command']:
 
694
                hook(self)
693
695
            self._operation = cleanup.OperationWithCleanups(class_run)
694
696
            try:
695
697
                return self._operation.run_simple(*args, **kwargs)
696
698
            finally:
697
699
                del self._operation
 
700
                for hook in Command.hooks['post_command']:
 
701
                    hook(self)
698
702
        self.run = run
699
703
 
700
704
    def run(self):
788
792
            " is safe to mutate - e.g. to remove a command. "
789
793
            "list_commands should return the updated set of command names.",
790
794
            (1, 17))
 
795
        self.add_hook('pre_command',
 
796
            "Called prior to executing a command. Called with the command "
 
797
            "object.", (2, 6))
 
798
        self.add_hook('post_command',
 
799
            "Called after executing a command. Called with the command "
 
800
            "object.", (2, 6))
791
801
 
792
802
Command.hooks = CommandHooks()
793
803
 
925
935
        exitcode = trace.report_exception(exc_info, sys.stderr)
926
936
        if os.environ.get('BZR_PDB'):
927
937
            print '**** entering debugger'
928
 
            tb = exc_info[2]
929
938
            import pdb
930
 
            if sys.version_info[:2] < (2, 6):
931
 
                # XXX: we want to do
932
 
                #    pdb.post_mortem(tb)
933
 
                # but because pdb.post_mortem gives bad results for tracebacks
934
 
                # from inside generators, we do it manually.
935
 
                # (http://bugs.python.org/issue4150, fixed in Python 2.6)
936
 
 
937
 
                # Setup pdb on the traceback
938
 
                p = pdb.Pdb()
939
 
                p.reset()
940
 
                p.setup(tb.tb_frame, tb)
941
 
                # Point the debugger at the deepest frame of the stack
942
 
                p.curindex = len(p.stack) - 1
943
 
                p.curframe = p.stack[p.curindex][0]
944
 
                # Start the pdb prompt.
945
 
                p.print_stack_entry(p.stack[p.curindex])
946
 
                p.execRcLines()
947
 
                p.cmdloop()
948
 
            else:
949
 
                pdb.post_mortem(tb)
 
939
            pdb.post_mortem(exc_info[2])
950
940
        return exitcode
951
941
 
952
942