/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-07 10:36:24 UTC
  • mfrom: (5764 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5766.
  • Revision ID: john@arbash-meinel.com-20110407103624-n76g6tjeqmznwdcd
Merge bzr.dev 5764 to resolve release-notes (aka NEWS) conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
222
219
    Use of all_command_names() is encouraged rather than builtin_command_names
223
220
    and/or plugin_command_names.
224
221
    """
 
222
    _register_builtin_commands()
225
223
    return builtin_command_registry.keys()
226
224
 
227
225
 
397
395
            will not mangled.
398
396
 
399
397
    :cvar hooks: An instance of CommandHooks.
 
398
    :ivar __doc__: The help shown by 'bzr help command' for this command.
 
399
        This is set by assigning explicitly to __doc__ so that -OO can
 
400
        be used::
 
401
 
 
402
        class Foo(Command):
 
403
            __doc__ = "My help goes here"
400
404
    """
401
405
    aliases = []
402
406
    takes_args = []
407
411
 
408
412
    def __init__(self):
409
413
        """Construct an instance of this command."""
410
 
        if self.__doc__ == Command.__doc__:
411
 
            warn("No help message set for %r" % self)
412
414
        # List of standard options directly supported
413
415
        self.supported_std_options = []
414
416
        self._setup_run()
482
484
            message explaining how to obtain full help.
483
485
        """
484
486
        doc = self.help()
485
 
        if doc is None:
486
 
            raise NotImplementedError("sorry, no detailed help yet for %r" % self.name())
 
487
        if not doc:
 
488
            doc = "No help for this command."
487
489
 
488
490
        # Extract the summary (purpose) and sections out from the text
489
491
        purpose,sections,order = self._get_help_parts(doc)
682
684
 
683
685
        self._setup_outf()
684
686
 
685
 
        return self.run(**all_cmd_args)
 
687
        try:
 
688
            return self.run(**all_cmd_args)
 
689
        finally:
 
690
            # reset it, so that other commands run in the same process won't
 
691
            # inherit state. Before we reset it, log any activity, so that it
 
692
            # gets properly tracked.
 
693
            ui.ui_factory.log_transport_activity(
 
694
                display=('bytes' in debug.debug_flags))
 
695
            trace.set_verbosity_level(0)
686
696
 
687
697
    def _setup_run(self):
688
698
        """Wrap the defined run method on self with a cleanup.
762
772
        These are all empty initially, because by default nothing should get
763
773
        notified.
764
774
        """
765
 
        Hooks.__init__(self)
766
 
        self.create_hook(HookPoint('extend_command',
 
775
        Hooks.__init__(self, "bzrlib.commands", "Command.hooks")
 
776
        self.add_hook('extend_command',
767
777
            "Called after creating a command object to allow modifications "
768
778
            "such as adding or removing options, docs etc. Called with the "
769
 
            "new bzrlib.commands.Command object.", (1, 13), None))
770
 
        self.create_hook(HookPoint('get_command',
 
779
            "new bzrlib.commands.Command object.", (1, 13))
 
780
        self.add_hook('get_command',
771
781
            "Called when creating a single command. Called with "
772
782
            "(cmd_or_None, command_name). get_command should either return "
773
783
            "the cmd_or_None parameter, or a replacement Command object that "
774
784
            "should be used for the command. Note that the Command.hooks "
775
785
            "hooks are core infrastructure. Many users will prefer to use "
776
786
            "bzrlib.commands.register_command or plugin_cmds.register_lazy.",
777
 
            (1, 17), None))
778
 
        self.create_hook(HookPoint('get_missing_command',
 
787
            (1, 17))
 
788
        self.add_hook('get_missing_command',
779
789
            "Called when creating a single command if no command could be "
780
790
            "found. Called with (command_name). get_missing_command should "
781
791
            "either return None, or a Command object to be used for the "
782
 
            "command.", (1, 17), None))
783
 
        self.create_hook(HookPoint('list_commands',
 
792
            "command.", (1, 17))
 
793
        self.add_hook('list_commands',
784
794
            "Called when enumerating commands. Called with a set of "
785
795
            "cmd_name strings for all the commands found so far. This set "
786
796
            " is safe to mutate - e.g. to remove a command. "
787
797
            "list_commands should return the updated set of command names.",
788
 
            (1, 17), None))
 
798
            (1, 17))
789
799
 
790
800
Command.hooks = CommandHooks()
791
801
 
805
815
    else:
806
816
        args = argv
807
817
 
808
 
    options, args = parser.parse_args(args)
 
818
    # for python 2.5 and later, optparse raises this exception if a non-ascii
 
819
    # option name is given.  See http://bugs.python.org/issue2931
 
820
    try:
 
821
        options, args = parser.parse_args(args)
 
822
    except UnicodeEncodeError,e:
 
823
        raise errors.BzrCommandError('Only ASCII permitted in option names')
 
824
 
809
825
    opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
810
826
                 v is not option.OptionParser.DEFAULT_VALUE])
811
827
    return args, opts
1050
1066
        elif a == '--coverage':
1051
1067
            opt_coverage_dir = argv[i + 1]
1052
1068
            i += 1
 
1069
        elif a == '--profile-imports':
 
1070
            pass # already handled in startup script Bug #588277
1053
1071
        elif a.startswith('-D'):
1054
1072
            debug.debug_flags.add(a[2:])
1055
1073
        else:
1077
1095
    if not opt_no_aliases:
1078
1096
        alias_argv = get_alias(argv[0])
1079
1097
        if alias_argv:
1080
 
            user_encoding = osutils.get_user_encoding()
1081
 
            alias_argv = [a.decode(user_encoding) for a in alias_argv]
1082
1098
            argv[0] = alias_argv.pop(0)
1083
1099
 
1084
1100
    cmd = argv.pop(0)
1085
 
    # We want only 'ascii' command names, but the user may have typed
1086
 
    # in a Unicode name. In that case, they should just get a
1087
 
    # 'command not found' error later.
1088
 
 
1089
1101
    cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
1090
1102
    run = cmd_obj.run_argv_aliases
1091
1103
    run_argv = [argv, alias_argv]
1190
1202
    argv = _specified_or_unicode_argv(argv)
1191
1203
    _register_builtin_commands()
1192
1204
    ret = run_bzr_catch_errors(argv)
1193
 
    bzrlib.ui.ui_factory.log_transport_activity(
1194
 
        display=('bytes' in debug.debug_flags))
1195
1205
    trace.mutter("return code %d", ret)
1196
1206
    return ret
1197
1207