~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

(jelmer) Use the absolute_import feature everywhere in bzrlib,
 and add a source test to make sure it's used everywhere. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
import bzrlib
35
35
from bzrlib import (
36
 
    config,
37
36
    cleanup,
38
37
    cmdline,
39
38
    debug,
690
689
        """
691
690
        class_run = self.run
692
691
        def run(*args, **kwargs):
693
 
            for hook in Command.hooks['pre_command']:
694
 
                hook(self)
695
692
            self._operation = cleanup.OperationWithCleanups(class_run)
696
693
            try:
697
694
                return self._operation.run_simple(*args, **kwargs)
698
695
            finally:
699
696
                del self._operation
700
 
                for hook in Command.hooks['post_command']:
701
 
                    hook(self)
702
697
        self.run = run
703
698
 
704
699
    def run(self):
792
787
            " is safe to mutate - e.g. to remove a command. "
793
788
            "list_commands should return the updated set of command names.",
794
789
            (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))
801
790
 
802
791
Command.hooks = CommandHooks()
803
792
 
935
924
        exitcode = trace.report_exception(exc_info, sys.stderr)
936
925
        if os.environ.get('BZR_PDB'):
937
926
            print '**** entering debugger'
 
927
            tb = exc_info[2]
938
928
            import pdb
939
 
            pdb.post_mortem(exc_info[2])
 
929
            if sys.version_info[:2] < (2, 6):
 
930
                # XXX: we want to do
 
931
                #    pdb.post_mortem(tb)
 
932
                # but because pdb.post_mortem gives bad results for tracebacks
 
933
                # from inside generators, we do it manually.
 
934
                # (http://bugs.python.org/issue4150, fixed in Python 2.6)
 
935
 
 
936
                # Setup pdb on the traceback
 
937
                p = pdb.Pdb()
 
938
                p.reset()
 
939
                p.setup(tb.tb_frame, tb)
 
940
                # Point the debugger at the deepest frame of the stack
 
941
                p.curindex = len(p.stack) - 1
 
942
                p.curframe = p.stack[p.curindex][0]
 
943
                # Start the pdb prompt.
 
944
                p.print_stack_entry(p.stack[p.curindex])
 
945
                p.execRcLines()
 
946
                p.cmdloop()
 
947
            else:
 
948
                pdb.post_mortem(tb)
940
949
        return exitcode
941
950
 
942
951
 
1062
1071
            argv_copy.append(a)
1063
1072
        i += 1
1064
1073
 
1065
 
    if bzrlib.global_state is None:
1066
 
        # FIXME: Workaround for users that imported bzrlib but didn't call
1067
 
        # bzrlib.initialize -- vila 2012-01-19
1068
 
        cmdline_overrides = config.CommandLineStore()
1069
 
    else:
1070
 
        cmdline_overrides = bzrlib.global_state.cmdline_overrides
1071
 
    cmdline_overrides._from_cmdline(override_config)
 
1074
    bzrlib.global_state.cmdline_overrides._from_cmdline(override_config)
1072
1075
 
1073
1076
    debug.set_debug_flags_from_config()
1074
1077
 
1128
1131
            trace.debug_memory('Process status after command:', short=False)
1129
1132
        option._verbosity_level = saved_verbosity_level
1130
1133
        # Reset the overrides 
1131
 
        cmdline_overrides._reset()
 
1134
        bzrlib.global_state.cmdline_overrides._reset()
1132
1135
 
1133
1136
 
1134
1137
def display_command(func):