~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 12:19:29 UTC
  • mfrom: (6437.23.11 2.5)
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: jelmer@samba.org-20120220121929-7ni2psvjoatm1yp4
Merge bzr/2.5.

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):
229
226
    try:
230
227
        return _get_cmd_object(cmd_name, plugins_override)
231
228
    except KeyError:
232
 
        raise errors.BzrCommandError('unknown command "%s"' % cmd_name)
 
229
        raise errors.BzrCommandError(gettext('unknown command "%s"') % cmd_name)
233
230
 
234
231
 
235
232
def _get_cmd_object(cmd_name, plugins_override=True, check_missing=True):
465
462
            usage help (e.g. Purpose, Usage, Options) with a
466
463
            message explaining how to obtain full help.
467
464
        """
468
 
        if self.l10n and not i18n.installed():
 
465
        if self.l10n:
469
466
            i18n.install()  # Install i18n only for get_help_text for now.
470
467
        doc = self.help()
471
468
        if doc:
554
551
                        see_also_links.append(item)
555
552
                    else:
556
553
                        # Use a Sphinx link for this entry
557
 
                        link_text = gettext(":doc:`%s <%s-help>`") % (item, item)
 
554
                        link_text = gettext(":doc:`{0} <{1}-help>`").format(
 
555
                                                                    item, item)
558
556
                        see_also_links.append(link_text)
559
557
                see_also = see_also_links
560
558
            result += gettext(':See also: %s') % ', '.join(see_also) + '\n'
662
660
            opts['quiet'] = trace.is_quiet()
663
661
        elif opts.has_key('quiet'):
664
662
            del opts['quiet']
665
 
 
666
663
        # mix arguments and options into one dictionary
667
664
        cmdargs = _match_argform(self.name(), self.takes_args, args)
668
665
        cmdopts = {}
815
812
    try:
816
813
        options, args = parser.parse_args(args)
817
814
    except UnicodeEncodeError,e:
818
 
        raise errors.BzrCommandError('Only ASCII permitted in option names')
 
815
        raise errors.BzrCommandError(
 
816
            gettext('Only ASCII permitted in option names'))
819
817
 
820
818
    opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
821
819
                 v is not option.OptionParser.DEFAULT_VALUE])
839
837
                argdict[argname + '_list'] = None
840
838
        elif ap[-1] == '+':
841
839
            if not args:
842
 
                raise errors.BzrCommandError("command %r needs one or more %s"
843
 
                                             % (cmd, argname.upper()))
 
840
                raise errors.BzrCommandError(gettext(
 
841
                      "command {0!r} needs one or more {1}").format(
 
842
                      cmd, argname.upper()))
844
843
            else:
845
844
                argdict[argname + '_list'] = args[:]
846
845
                args = []
847
846
        elif ap[-1] == '$': # all but one
848
847
            if len(args) < 2:
849
 
                raise errors.BzrCommandError("command %r needs one or more %s"
850
 
                                             % (cmd, argname.upper()))
 
848
                raise errors.BzrCommandError(
 
849
                      gettext("command {0!r} needs one or more {1}").format(
 
850
                                             cmd, argname.upper()))
851
851
            argdict[argname + '_list'] = args[:-1]
852
852
            args[:-1] = []
853
853
        else:
854
854
            # just a plain arg
855
855
            argname = ap
856
856
            if not args:
857
 
                raise errors.BzrCommandError("command %r requires argument %s"
858
 
                               % (cmd, argname.upper()))
 
857
                raise errors.BzrCommandError(
 
858
                     gettext("command {0!r} requires argument {1}").format(
 
859
                               cmd, argname.upper()))
859
860
            else:
860
861
                argdict[argname] = args.pop(0)
861
862
 
862
863
    if args:
863
 
        raise errors.BzrCommandError("extra argument to command %s: %s"
864
 
                                     % (cmd, args[0]))
 
864
        raise errors.BzrCommandError( gettext(
 
865
                              "extra argument to command {0}: {1}").format(
 
866
                                       cmd, args[0]) )
865
867
 
866
868
    return argdict
867
869
 
957
959
        stats.pprint()
958
960
    else:
959
961
        stats.save(filename)
960
 
        trace.note('Profile data written to "%s".', filename)
 
962
        trace.note(gettext('Profile data written to "%s".'), filename)
961
963
    return ret
962
964
 
963
965
 
1035
1037
 
1036
1038
    argv_copy = []
1037
1039
    i = 0
 
1040
    override_config = []
1038
1041
    while i < len(argv):
1039
1042
        a = argv[i]
1040
1043
        if a == '--profile':
1063
1066
            pass # already handled in startup script Bug #588277
1064
1067
        elif a.startswith('-D'):
1065
1068
            debug.debug_flags.add(a[2:])
 
1069
        elif a.startswith('-O'):
 
1070
            override_config.append(a[2:])
1066
1071
        else:
1067
1072
            argv_copy.append(a)
1068
1073
        i += 1
1069
1074
 
 
1075
    if bzrlib.global_state is None:
 
1076
        # FIXME: Workaround for users that imported bzrlib but didn't call
 
1077
        # bzrlib.initialize -- vila 2012-01-19
 
1078
        cmdline_overrides = config.CommandLineStore()
 
1079
    else:
 
1080
        cmdline_overrides = bzrlib.global_state.cmdline_overrides
 
1081
    cmdline_overrides._from_cmdline(override_config)
 
1082
 
1070
1083
    debug.set_debug_flags_from_config()
1071
1084
 
1072
1085
    if not opt_no_plugins:
1124
1137
        if 'memory' in debug.debug_flags:
1125
1138
            trace.debug_memory('Process status after command:', short=False)
1126
1139
        option._verbosity_level = saved_verbosity_level
 
1140
        # Reset the overrides 
 
1141
        cmdline_overrides._reset()
1127
1142
 
1128
1143
 
1129
1144
def display_command(func):
1158
1173
        "bzr plugin commands")
1159
1174
    Command.hooks.install_named_hook("get_command", _get_external_command,
1160
1175
        "bzr external command lookup")
1161
 
    Command.hooks.install_named_hook("get_missing_command", _try_plugin_provider,
1162
 
        "bzr plugin-provider-db check")
 
1176
    Command.hooks.install_named_hook("get_missing_command",
 
1177
                                     _try_plugin_provider,
 
1178
                                     "bzr plugin-provider-db check")
1163
1179
 
1164
1180
 
1165
1181