~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-10 07:46:15 UTC
  • mfrom: (5844 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5845.
  • Revision ID: jelmer@samba.org-20110510074615-eptod049ndjxc4i7
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
from bzrlib.lazy_import import lazy_import
29
29
lazy_import(globals(), """
30
 
import codecs
31
30
import errno
32
31
import threading
33
 
from warnings import warn
34
32
 
35
33
import bzrlib
36
34
from bzrlib import (
42
40
    osutils,
43
41
    trace,
44
42
    ui,
45
 
    win32utils,
46
43
    )
47
44
""")
48
45
 
49
 
from bzrlib.hooks import HookPoint, Hooks
 
46
from bzrlib.hooks import Hooks
50
47
# Compatibility - Option used to be in commands.
51
48
from bzrlib.option import Option
52
49
from bzrlib.plugin import disable_plugins, load_plugins
276
273
    # Allow plugins to extend commands
277
274
    for hook in Command.hooks['extend_command']:
278
275
        hook(cmd)
 
276
    if getattr(cmd, 'invoked_as', None) is None:
 
277
        cmd.invoked_as = cmd_name
279
278
    return cmd
280
279
 
281
280
 
397
396
            sys.stdout is forced to be a binary stream, and line-endings
398
397
            will not mangled.
399
398
 
 
399
    :ivar invoked_as:
 
400
        A string indicating the real name under which this command was
 
401
        invoked, before expansion of aliases. 
 
402
        (This may be None if the command was constructed and run in-process.)
 
403
 
400
404
    :cvar hooks: An instance of CommandHooks.
 
405
 
401
406
    :ivar __doc__: The help shown by 'bzr help command' for this command.
402
407
        This is set by assigning explicitly to __doc__ so that -OO can
403
408
        be used::
409
414
    takes_args = []
410
415
    takes_options = []
411
416
    encoding_type = 'strict'
 
417
    invoked_as = None
412
418
 
413
419
    hidden = False
414
420
 
752
758
        return getdoc(self)
753
759
 
754
760
    def name(self):
 
761
        """Return the canonical name for this command.
 
762
 
 
763
        The name under which it was actually invoked is available in invoked_as.
 
764
        """
755
765
        return _unsquish_command_name(self.__class__.__name__)
756
766
 
757
767
    def plugin_name(self):
775
785
        These are all empty initially, because by default nothing should get
776
786
        notified.
777
787
        """
778
 
        Hooks.__init__(self)
779
 
        self.create_hook(HookPoint('extend_command',
 
788
        Hooks.__init__(self, "bzrlib.commands", "Command.hooks")
 
789
        self.add_hook('extend_command',
780
790
            "Called after creating a command object to allow modifications "
781
791
            "such as adding or removing options, docs etc. Called with the "
782
 
            "new bzrlib.commands.Command object.", (1, 13), None))
783
 
        self.create_hook(HookPoint('get_command',
 
792
            "new bzrlib.commands.Command object.", (1, 13))
 
793
        self.add_hook('get_command',
784
794
            "Called when creating a single command. Called with "
785
795
            "(cmd_or_None, command_name). get_command should either return "
786
796
            "the cmd_or_None parameter, or a replacement Command object that "
787
797
            "should be used for the command. Note that the Command.hooks "
788
798
            "hooks are core infrastructure. Many users will prefer to use "
789
799
            "bzrlib.commands.register_command or plugin_cmds.register_lazy.",
790
 
            (1, 17), None))
791
 
        self.create_hook(HookPoint('get_missing_command',
 
800
            (1, 17))
 
801
        self.add_hook('get_missing_command',
792
802
            "Called when creating a single command if no command could be "
793
803
            "found. Called with (command_name). get_missing_command should "
794
804
            "either return None, or a Command object to be used for the "
795
 
            "command.", (1, 17), None))
796
 
        self.create_hook(HookPoint('list_commands',
 
805
            "command.", (1, 17))
 
806
        self.add_hook('list_commands',
797
807
            "Called when enumerating commands. Called with a set of "
798
808
            "cmd_name strings for all the commands found so far. This set "
799
809
            " is safe to mutate - e.g. to remove a command. "
800
810
            "list_commands should return the updated set of command names.",
801
 
            (1, 17), None))
 
811
            (1, 17))
802
812
 
803
813
Command.hooks = CommandHooks()
804
814
 
1034
1044
        Specify the number of processes that can be run concurrently (selftest).
1035
1045
    """
1036
1046
    trace.mutter("bazaar version: " + bzrlib.__version__)
1037
 
    argv = list(argv)
 
1047
    argv = _specified_or_unicode_argv(argv)
1038
1048
    trace.mutter("bzr arguments: %r", argv)
1039
1049
 
1040
1050
    opt_lsprof = opt_profile = opt_no_plugins = opt_builtin =  \
1180
1190
        new_argv = []
1181
1191
        try:
1182
1192
            # ensure all arguments are unicode strings
1183
 
            for a in argv[1:]:
 
1193
            for a in argv:
1184
1194
                if isinstance(a, unicode):
1185
1195
                    new_argv.append(a)
1186
1196
                else:
1202
1212
 
1203
1213
    :return: exit code of bzr command.
1204
1214
    """
1205
 
    argv = _specified_or_unicode_argv(argv)
 
1215
    if argv is not None:
 
1216
        argv = argv[1:]
1206
1217
    _register_builtin_commands()
1207
1218
    ret = run_bzr_catch_errors(argv)
1208
1219
    trace.mutter("return code %d", ret)