~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

(gz) Fix deprecations of win32utils path function unicode wrappers (Martin
 Packman)

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
50
51
from bzrlib.option import Option
51
52
from bzrlib.plugin import disable_plugins, load_plugins
52
53
from bzrlib import registry
53
 
from bzrlib.symbol_versioning import (
54
 
    deprecated_function,
55
 
    deprecated_in,
56
 
    deprecated_method,
57
 
    )
58
54
 
59
55
 
60
56
class CommandInfo(object):
164
160
    return cmd[4:].replace('_','-')
165
161
 
166
162
 
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
163
def _register_builtin_commands():
178
164
    if builtin_command_registry.keys():
179
165
        # only load once
239
225
    try:
240
226
        return _get_cmd_object(cmd_name, plugins_override)
241
227
    except KeyError:
242
 
        raise errors.BzrCommandError('unknown command "%s"' % cmd_name)
 
228
        raise errors.BzrCommandError(gettext('unknown command "%s"') % cmd_name)
243
229
 
244
230
 
245
231
def _get_cmd_object(cmd_name, plugins_override=True, check_missing=True):
442
428
        """
443
429
        self._operation.cleanup_now()
444
430
 
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
431
    def _usage(self):
459
432
        """Return single-line grammar for this command.
460
433
 
488
461
            usage help (e.g. Purpose, Usage, Options) with a
489
462
            message explaining how to obtain full help.
490
463
        """
491
 
        if self.l10n and not i18n.installed():
 
464
        if self.l10n:
492
465
            i18n.install()  # Install i18n only for get_help_text for now.
493
466
        doc = self.help()
494
467
        if doc:
577
550
                        see_also_links.append(item)
578
551
                    else:
579
552
                        # Use a Sphinx link for this entry
580
 
                        link_text = gettext(":doc:`%s <%s-help>`") % (item, item)
 
553
                        link_text = gettext(":doc:`{0} <{1}-help>`").format(
 
554
                                                                    item, item)
581
555
                        see_also_links.append(link_text)
582
556
                see_also = see_also_links
583
557
            result += gettext(':See also: %s') % ', '.join(see_also) + '\n'
685
659
            opts['quiet'] = trace.is_quiet()
686
660
        elif opts.has_key('quiet'):
687
661
            del opts['quiet']
688
 
 
689
662
        # mix arguments and options into one dictionary
690
663
        cmdargs = _match_argform(self.name(), self.takes_args, args)
691
664
        cmdopts = {}
723
696
                del self._operation
724
697
        self.run = run
725
698
 
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
699
    def run(self):
732
700
        """Actually run the command.
733
701
 
843
811
    try:
844
812
        options, args = parser.parse_args(args)
845
813
    except UnicodeEncodeError,e:
846
 
        raise errors.BzrCommandError('Only ASCII permitted in option names')
 
814
        raise errors.BzrCommandError(
 
815
            gettext('Only ASCII permitted in option names'))
847
816
 
848
817
    opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
849
818
                 v is not option.OptionParser.DEFAULT_VALUE])
867
836
                argdict[argname + '_list'] = None
868
837
        elif ap[-1] == '+':
869
838
            if not args:
870
 
                raise errors.BzrCommandError("command %r needs one or more %s"
871
 
                                             % (cmd, argname.upper()))
 
839
                raise errors.BzrCommandError(gettext(
 
840
                      "command {0!r} needs one or more {1}").format(
 
841
                      cmd, argname.upper()))
872
842
            else:
873
843
                argdict[argname + '_list'] = args[:]
874
844
                args = []
875
845
        elif ap[-1] == '$': # all but one
876
846
            if len(args) < 2:
877
 
                raise errors.BzrCommandError("command %r needs one or more %s"
878
 
                                             % (cmd, argname.upper()))
 
847
                raise errors.BzrCommandError(
 
848
                      gettext("command {0!r} needs one or more {1}").format(
 
849
                                             cmd, argname.upper()))
879
850
            argdict[argname + '_list'] = args[:-1]
880
851
            args[:-1] = []
881
852
        else:
882
853
            # just a plain arg
883
854
            argname = ap
884
855
            if not args:
885
 
                raise errors.BzrCommandError("command %r requires argument %s"
886
 
                               % (cmd, argname.upper()))
 
856
                raise errors.BzrCommandError(
 
857
                     gettext("command {0!r} requires argument {1}").format(
 
858
                               cmd, argname.upper()))
887
859
            else:
888
860
                argdict[argname] = args.pop(0)
889
861
 
890
862
    if args:
891
 
        raise errors.BzrCommandError("extra argument to command %s: %s"
892
 
                                     % (cmd, args[0]))
 
863
        raise errors.BzrCommandError( gettext(
 
864
                              "extra argument to command {0}: {1}").format(
 
865
                                       cmd, args[0]) )
893
866
 
894
867
    return argdict
895
868
 
978
951
 
979
952
def apply_lsprofiled(filename, the_callable, *args, **kwargs):
980
953
    from bzrlib.lsprof import profile
981
 
    ret, stats = profile(exception_to_return_code, the_callable, *args, **kwargs)
 
954
    ret, stats = profile(exception_to_return_code, the_callable,
 
955
                         *args, **kwargs)
982
956
    stats.sort()
983
957
    if filename is None:
984
958
        stats.pprint()
985
959
    else:
986
960
        stats.save(filename)
987
 
        trace.note('Profile data written to "%s".', filename)
 
961
        trace.note(gettext('Profile data written to "%s".'), filename)
988
962
    return ret
989
963
 
990
964
 
991
 
@deprecated_function(deprecated_in((2, 2, 0)))
992
 
def shlex_split_unicode(unsplit):
993
 
    return cmdline.split(unsplit)
994
 
 
995
 
 
996
965
def get_alias(cmd, config=None):
997
966
    """Return an expanded alias, or None if no alias exists.
998
967
 
1067
1036
 
1068
1037
    argv_copy = []
1069
1038
    i = 0
 
1039
    override_config = []
1070
1040
    while i < len(argv):
1071
1041
        a = argv[i]
1072
1042
        if a == '--profile':
1095
1065
            pass # already handled in startup script Bug #588277
1096
1066
        elif a.startswith('-D'):
1097
1067
            debug.debug_flags.add(a[2:])
 
1068
        elif a.startswith('-O'):
 
1069
            override_config.append(a[2:])
1098
1070
        else:
1099
1071
            argv_copy.append(a)
1100
1072
        i += 1
1101
1073
 
 
1074
    bzrlib.global_state.cmdline_overrides._from_cmdline(override_config)
 
1075
 
1102
1076
    debug.set_debug_flags_from_config()
1103
1077
 
1104
1078
    if not opt_no_plugins:
1156
1130
        if 'memory' in debug.debug_flags:
1157
1131
            trace.debug_memory('Process status after command:', short=False)
1158
1132
        option._verbosity_level = saved_verbosity_level
 
1133
        # Reset the overrides 
 
1134
        bzrlib.global_state.cmdline_overrides._reset()
1159
1135
 
1160
1136
 
1161
1137
def display_command(func):
1190
1166
        "bzr plugin commands")
1191
1167
    Command.hooks.install_named_hook("get_command", _get_external_command,
1192
1168
        "bzr external command lookup")
1193
 
    Command.hooks.install_named_hook("get_missing_command", _try_plugin_provider,
1194
 
        "bzr plugin-provider-db check")
 
1169
    Command.hooks.install_named_hook("get_missing_command",
 
1170
                                     _try_plugin_provider,
 
1171
                                     "bzr plugin-provider-db check")
1195
1172
 
1196
1173
 
1197
1174