~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Patch Queue Manager
  • Date: 2016-01-31 13:36:59 UTC
  • mfrom: (6613.1.5 1538480-match-hostname)
  • Revision ID: pqm@pqm.ubuntu.com-20160131133659-ouy92ee2wlv9xz8m
(vila) Use ssl.match_hostname instead of our own. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
17
18
 
18
19
# TODO: Define arguments by objects, rather than just using names.
19
20
# Those objects can specify the expected type of the argument, which
32
33
 
33
34
import bzrlib
34
35
from bzrlib import (
 
36
    config,
35
37
    cleanup,
36
38
    cmdline,
37
39
    debug,
50
52
from bzrlib.option import Option
51
53
from bzrlib.plugin import disable_plugins, load_plugins
52
54
from bzrlib import registry
53
 
from bzrlib.symbol_versioning import (
54
 
    deprecated_function,
55
 
    deprecated_in,
56
 
    deprecated_method,
57
 
    )
58
55
 
59
56
 
60
57
class CommandInfo(object):
693
690
        """
694
691
        class_run = self.run
695
692
        def run(*args, **kwargs):
 
693
            for hook in Command.hooks['pre_command']:
 
694
                hook(self)
696
695
            self._operation = cleanup.OperationWithCleanups(class_run)
697
696
            try:
698
697
                return self._operation.run_simple(*args, **kwargs)
699
698
            finally:
700
699
                del self._operation
 
700
                for hook in Command.hooks['post_command']:
 
701
                    hook(self)
701
702
        self.run = run
702
703
 
703
704
    def run(self):
791
792
            " is safe to mutate - e.g. to remove a command. "
792
793
            "list_commands should return the updated set of command names.",
793
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))
794
801
 
795
802
Command.hooks = CommandHooks()
796
803
 
928
935
        exitcode = trace.report_exception(exc_info, sys.stderr)
929
936
        if os.environ.get('BZR_PDB'):
930
937
            print '**** entering debugger'
931
 
            tb = exc_info[2]
932
938
            import pdb
933
 
            if sys.version_info[:2] < (2, 6):
934
 
                # XXX: we want to do
935
 
                #    pdb.post_mortem(tb)
936
 
                # but because pdb.post_mortem gives bad results for tracebacks
937
 
                # from inside generators, we do it manually.
938
 
                # (http://bugs.python.org/issue4150, fixed in Python 2.6)
939
 
 
940
 
                # Setup pdb on the traceback
941
 
                p = pdb.Pdb()
942
 
                p.reset()
943
 
                p.setup(tb.tb_frame, tb)
944
 
                # Point the debugger at the deepest frame of the stack
945
 
                p.curindex = len(p.stack) - 1
946
 
                p.curframe = p.stack[p.curindex][0]
947
 
                # Start the pdb prompt.
948
 
                p.print_stack_entry(p.stack[p.curindex])
949
 
                p.execRcLines()
950
 
                p.cmdloop()
951
 
            else:
952
 
                pdb.post_mortem(tb)
 
939
            pdb.post_mortem(exc_info[2])
953
940
        return exitcode
954
941
 
955
942
 
1075
1062
            argv_copy.append(a)
1076
1063
        i += 1
1077
1064
 
1078
 
    bzrlib.global_state.cmdline_overrides._from_cmdline(override_config)
 
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)
1079
1072
 
1080
1073
    debug.set_debug_flags_from_config()
1081
1074
 
1135
1128
            trace.debug_memory('Process status after command:', short=False)
1136
1129
        option._verbosity_level = saved_verbosity_level
1137
1130
        # Reset the overrides 
1138
 
        bzrlib.global_state.cmdline_overrides._reset()
 
1131
        cmdline_overrides._reset()
1139
1132
 
1140
1133
 
1141
1134
def display_command(func):