~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:
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):
663
660
            opts['quiet'] = trace.is_quiet()
664
661
        elif opts.has_key('quiet'):
665
662
            del opts['quiet']
666
 
 
667
663
        # mix arguments and options into one dictionary
668
664
        cmdargs = _match_argform(self.name(), self.takes_args, args)
669
665
        cmdopts = {}
694
690
        """
695
691
        class_run = self.run
696
692
        def run(*args, **kwargs):
 
693
            for hook in Command.hooks['pre_command']:
 
694
                hook(self)
697
695
            self._operation = cleanup.OperationWithCleanups(class_run)
698
696
            try:
699
697
                return self._operation.run_simple(*args, **kwargs)
700
698
            finally:
701
699
                del self._operation
 
700
                for hook in Command.hooks['post_command']:
 
701
                    hook(self)
702
702
        self.run = run
703
703
 
704
704
    def run(self):
792
792
            " is safe to mutate - e.g. to remove a command. "
793
793
            "list_commands should return the updated set of command names.",
794
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))
795
801
 
796
802
Command.hooks = CommandHooks()
797
803
 
816
822
    try:
817
823
        options, args = parser.parse_args(args)
818
824
    except UnicodeEncodeError,e:
819
 
        raise errors.BzrCommandError(gettext('Only ASCII permitted in option names'))
 
825
        raise errors.BzrCommandError(
 
826
            gettext('Only ASCII permitted in option names'))
820
827
 
821
828
    opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
822
829
                 v is not option.OptionParser.DEFAULT_VALUE])
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
 
1040
1027
 
1041
1028
    argv_copy = []
1042
1029
    i = 0
 
1030
    override_config = []
1043
1031
    while i < len(argv):
1044
1032
        a = argv[i]
1045
1033
        if a == '--profile':
1068
1056
            pass # already handled in startup script Bug #588277
1069
1057
        elif a.startswith('-D'):
1070
1058
            debug.debug_flags.add(a[2:])
 
1059
        elif a.startswith('-O'):
 
1060
            override_config.append(a[2:])
1071
1061
        else:
1072
1062
            argv_copy.append(a)
1073
1063
        i += 1
1074
1064
 
 
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)
 
1072
 
1075
1073
    debug.set_debug_flags_from_config()
1076
1074
 
1077
1075
    if not opt_no_plugins:
1129
1127
        if 'memory' in debug.debug_flags:
1130
1128
            trace.debug_memory('Process status after command:', short=False)
1131
1129
        option._verbosity_level = saved_verbosity_level
 
1130
        # Reset the overrides 
 
1131
        cmdline_overrides._reset()
1132
1132
 
1133
1133
 
1134
1134
def display_command(func):
1163
1163
        "bzr plugin commands")
1164
1164
    Command.hooks.install_named_hook("get_command", _get_external_command,
1165
1165
        "bzr external command lookup")
1166
 
    Command.hooks.install_named_hook("get_missing_command", _try_plugin_provider,
1167
 
        "bzr plugin-provider-db check")
 
1166
    Command.hooks.install_named_hook("get_missing_command",
 
1167
                                     _try_plugin_provider,
 
1168
                                     "bzr plugin-provider-db check")
1168
1169
 
1169
1170
 
1170
1171