~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

Revert the dirstate/transform changes, so we have a pure 'lstat/fstat' change.

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