~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Patch Queue Manager
  • Date: 2011-10-09 13:52:06 UTC
  • mfrom: (6202.1.3 revno-revision)
  • Revision ID: pqm@pqm.ubuntu.com-20111009135206-t3utsln6mtzv9eut
(jelmer) Add a --revision argument to 'bzr revno'. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
164
164
    return cmd[4:].replace('_','-')
165
165
 
166
166
 
167
 
@deprecated_function(deprecated_in((2, 2, 0)))
168
 
def _builtin_commands():
169
 
    """Return a dict of {name: cmd_class} for builtin commands.
170
 
 
171
 
    :deprecated: Use the builtin_command_registry registry instead
172
 
    """
173
 
    # return dict(name: cmd_class)
174
 
    return dict(builtin_command_registry.items())
175
 
 
176
 
 
177
167
def _register_builtin_commands():
178
168
    if builtin_command_registry.keys():
179
169
        # only load once
239
229
    try:
240
230
        return _get_cmd_object(cmd_name, plugins_override)
241
231
    except KeyError:
242
 
        raise errors.BzrCommandError('unknown command "%s"' % cmd_name)
 
232
        raise errors.BzrCommandError(gettext('unknown command "%s"') % cmd_name)
243
233
 
244
234
 
245
235
def _get_cmd_object(cmd_name, plugins_override=True, check_missing=True):
442
432
        """
443
433
        self._operation.cleanup_now()
444
434
 
445
 
    @deprecated_method(deprecated_in((2, 1, 0)))
446
 
    def _maybe_expand_globs(self, file_list):
447
 
        """Glob expand file_list if the platform does not do that itself.
448
 
 
449
 
        Not used anymore, now that the bzr command-line parser globs on
450
 
        Windows.
451
 
 
452
 
        :return: A possibly empty list of unicode paths.
453
 
 
454
 
        Introduced in bzrlib 0.18.
455
 
        """
456
 
        return file_list
457
 
 
458
435
    def _usage(self):
459
436
        """Return single-line grammar for this command.
460
437
 
488
465
            usage help (e.g. Purpose, Usage, Options) with a
489
466
            message explaining how to obtain full help.
490
467
        """
491
 
        if self.l10n and not i18n.installed():
 
468
        if self.l10n:
492
469
            i18n.install()  # Install i18n only for get_help_text for now.
493
470
        doc = self.help()
494
471
        if doc:
577
554
                        see_also_links.append(item)
578
555
                    else:
579
556
                        # Use a Sphinx link for this entry
580
 
                        link_text = gettext(":doc:`%s <%s-help>`") % (item, item)
 
557
                        link_text = gettext(":doc:`{0} <{1}-help>`").format(
 
558
                                                                    item, item)
581
559
                        see_also_links.append(link_text)
582
560
                see_also = see_also_links
583
561
            result += gettext(':See also: %s') % ', '.join(see_also) + '\n'
685
663
            opts['quiet'] = trace.is_quiet()
686
664
        elif opts.has_key('quiet'):
687
665
            del opts['quiet']
688
 
 
689
666
        # mix arguments and options into one dictionary
690
667
        cmdargs = _match_argform(self.name(), self.takes_args, args)
691
668
        cmdopts = {}
723
700
                del self._operation
724
701
        self.run = run
725
702
 
726
 
    @deprecated_method(deprecated_in((2, 2, 0)))
727
 
    def run_direct(self, *args, **kwargs):
728
 
        """Deprecated thunk from bzrlib 2.1."""
729
 
        return self.run(*args, **kwargs)
730
 
 
731
703
    def run(self):
732
704
        """Actually run the command.
733
705
 
843
815
    try:
844
816
        options, args = parser.parse_args(args)
845
817
    except UnicodeEncodeError,e:
846
 
        raise errors.BzrCommandError('Only ASCII permitted in option names')
 
818
        raise errors.BzrCommandError(
 
819
            gettext('Only ASCII permitted in option names'))
847
820
 
848
821
    opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
849
822
                 v is not option.OptionParser.DEFAULT_VALUE])
867
840
                argdict[argname + '_list'] = None
868
841
        elif ap[-1] == '+':
869
842
            if not args:
870
 
                raise errors.BzrCommandError("command %r needs one or more %s"
871
 
                                             % (cmd, argname.upper()))
 
843
                raise errors.BzrCommandError(gettext(
 
844
                      "command {0!r} needs one or more {1}").format(
 
845
                      cmd, argname.upper()))
872
846
            else:
873
847
                argdict[argname + '_list'] = args[:]
874
848
                args = []
875
849
        elif ap[-1] == '$': # all but one
876
850
            if len(args) < 2:
877
 
                raise errors.BzrCommandError("command %r needs one or more %s"
878
 
                                             % (cmd, argname.upper()))
 
851
                raise errors.BzrCommandError(
 
852
                      gettext("command {0!r} needs one or more {1}").format(
 
853
                                             cmd, argname.upper()))
879
854
            argdict[argname + '_list'] = args[:-1]
880
855
            args[:-1] = []
881
856
        else:
882
857
            # just a plain arg
883
858
            argname = ap
884
859
            if not args:
885
 
                raise errors.BzrCommandError("command %r requires argument %s"
886
 
                               % (cmd, argname.upper()))
 
860
                raise errors.BzrCommandError(
 
861
                     gettext("command {0!r} requires argument {1}").format(
 
862
                               cmd, argname.upper()))
887
863
            else:
888
864
                argdict[argname] = args.pop(0)
889
865
 
890
866
    if args:
891
 
        raise errors.BzrCommandError("extra argument to command %s: %s"
892
 
                                     % (cmd, args[0]))
 
867
        raise errors.BzrCommandError( gettext(
 
868
                              "extra argument to command {0}: {1}").format(
 
869
                                       cmd, args[0]) )
893
870
 
894
871
    return argdict
895
872
 
978
955
 
979
956
def apply_lsprofiled(filename, the_callable, *args, **kwargs):
980
957
    from bzrlib.lsprof import profile
981
 
    ret, stats = profile(exception_to_return_code, the_callable, *args, **kwargs)
 
958
    ret, stats = profile(exception_to_return_code, the_callable,
 
959
                         *args, **kwargs)
982
960
    stats.sort()
983
961
    if filename is None:
984
962
        stats.pprint()
985
963
    else:
986
964
        stats.save(filename)
987
 
        trace.note('Profile data written to "%s".', filename)
 
965
        trace.note(gettext('Profile data written to "%s".'), filename)
988
966
    return ret
989
967
 
990
968
 
991
 
@deprecated_function(deprecated_in((2, 2, 0)))
992
 
def shlex_split_unicode(unsplit):
993
 
    return cmdline.split(unsplit)
994
 
 
995
 
 
996
969
def get_alias(cmd, config=None):
997
970
    """Return an expanded alias, or None if no alias exists.
998
971
 
1067
1040
 
1068
1041
    argv_copy = []
1069
1042
    i = 0
 
1043
    override_config = []
1070
1044
    while i < len(argv):
1071
1045
        a = argv[i]
1072
1046
        if a == '--profile':
1095
1069
            pass # already handled in startup script Bug #588277
1096
1070
        elif a.startswith('-D'):
1097
1071
            debug.debug_flags.add(a[2:])
 
1072
        elif a.startswith('-O'):
 
1073
            override_config.append(a[2:])
1098
1074
        else:
1099
1075
            argv_copy.append(a)
1100
1076
        i += 1
1101
1077
 
 
1078
    bzrlib.global_state.cmdline_overrides._from_cmdline(override_config)
 
1079
 
1102
1080
    debug.set_debug_flags_from_config()
1103
1081
 
1104
1082
    if not opt_no_plugins:
1156
1134
        if 'memory' in debug.debug_flags:
1157
1135
            trace.debug_memory('Process status after command:', short=False)
1158
1136
        option._verbosity_level = saved_verbosity_level
 
1137
        # Reset the overrides 
 
1138
        bzrlib.global_state.cmdline_overrides._reset()
1159
1139
 
1160
1140
 
1161
1141
def display_command(func):
1190
1170
        "bzr plugin commands")
1191
1171
    Command.hooks.install_named_hook("get_command", _get_external_command,
1192
1172
        "bzr external command lookup")
1193
 
    Command.hooks.install_named_hook("get_missing_command", _try_plugin_provider,
1194
 
        "bzr plugin-provider-db check")
 
1173
    Command.hooks.install_named_hook("get_missing_command",
 
1174
                                     _try_plugin_provider,
 
1175
                                     "bzr plugin-provider-db check")
1195
1176
 
1196
1177
 
1197
1178