/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: Vincent Ladeuil
  • Date: 2011-05-17 15:14:38 UTC
  • mfrom: (5050.73.3 2.2)
  • mto: (5609.39.5 2.3)
  • mto: This revision was merged to the branch mainline in revision 5885.
  • Revision ID: v.ladeuil+lp@free.fr-20110517151438-j75xuw2zm9alk9a5
Merge 2.2 into 2.3 resolving 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
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)
509
514
        # so we get <https://bugs.launchpad.net/bzr/+bug/249908>.  -- mbp
510
515
        # 20090319
511
516
        options = option.get_optparser(self.options()).format_option_help()
512
 
        # XXX: According to the spec, ReST option lists actually don't support 
513
 
        # options like --1.9 so that causes syntax errors (in Sphinx at least).
514
 
        # As that pattern always appears in the commands that break, we trap
515
 
        # on that and then format that block of 'format' options as a literal
516
 
        # block.
517
 
        if not plain and options.find('  --1.9  ') != -1:
 
517
        # FIXME: According to the spec, ReST option lists actually don't
 
518
        # support options like --1.14 so that causes syntax errors (in Sphinx
 
519
        # at least).  As that pattern always appears in the commands that
 
520
        # break, we trap on that and then format that block of 'format' options
 
521
        # as a literal block. We use the most recent format still listed so we
 
522
        # don't have to do that too often -- vila 20110514
 
523
        if not plain and options.find('  --1.14  ') != -1:
518
524
            options = options.replace(' format:\n', ' format::\n\n', 1)
519
525
        if options.startswith('Options:'):
520
526
            result += ':' + options
682
688
 
683
689
        self._setup_outf()
684
690
 
685
 
        return self.run(**all_cmd_args)
 
691
        try:
 
692
            return self.run(**all_cmd_args)
 
693
        finally:
 
694
            # reset it, so that other commands run in the same process won't
 
695
            # inherit state. Before we reset it, log any activity, so that it
 
696
            # gets properly tracked.
 
697
            ui.ui_factory.log_transport_activity(
 
698
                display=('bytes' in debug.debug_flags))
 
699
            trace.set_verbosity_level(0)
686
700
 
687
701
    def _setup_run(self):
688
702
        """Wrap the defined run method on self with a cleanup.
805
819
    else:
806
820
        args = argv
807
821
 
808
 
    options, args = parser.parse_args(args)
 
822
    # for python 2.5 and later, optparse raises this exception if a non-ascii
 
823
    # option name is given.  See http://bugs.python.org/issue2931
 
824
    try:
 
825
        options, args = parser.parse_args(args)
 
826
    except UnicodeEncodeError,e:
 
827
        raise errors.BzrCommandError('Only ASCII permitted in option names')
 
828
 
809
829
    opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
810
830
                 v is not option.OptionParser.DEFAULT_VALUE])
811
831
    return args, opts
1050
1070
        elif a == '--coverage':
1051
1071
            opt_coverage_dir = argv[i + 1]
1052
1072
            i += 1
 
1073
        elif a == '--profile-imports':
 
1074
            pass # already handled in startup script Bug #588277
1053
1075
        elif a.startswith('-D'):
1054
1076
            debug.debug_flags.add(a[2:])
1055
1077
        else:
1077
1099
    if not opt_no_aliases:
1078
1100
        alias_argv = get_alias(argv[0])
1079
1101
        if alias_argv:
1080
 
            user_encoding = osutils.get_user_encoding()
1081
 
            alias_argv = [a.decode(user_encoding) for a in alias_argv]
1082
1102
            argv[0] = alias_argv.pop(0)
1083
1103
 
1084
1104
    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
1105
    cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
1090
1106
    run = cmd_obj.run_argv_aliases
1091
1107
    run_argv = [argv, alias_argv]
1190
1206
    argv = _specified_or_unicode_argv(argv)
1191
1207
    _register_builtin_commands()
1192
1208
    ret = run_bzr_catch_errors(argv)
1193
 
    bzrlib.ui.ui_factory.log_transport_activity(
1194
 
        display=('bytes' in debug.debug_flags))
1195
1209
    trace.mutter("return code %d", ret)
1196
1210
    return ret
1197
1211