/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 breezy/commands.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 19:09:26 UTC
  • mfrom: (6622.1.36 breezy)
  • Revision ID: jelmer@jelmer.uk-20170521190926-5vtz8xaf0e9ylrpc
Merge rename to breezy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import os
27
27
import sys
28
28
 
29
 
from bzrlib.lazy_import import lazy_import
 
29
from breezy.lazy_import import lazy_import
30
30
lazy_import(globals(), """
31
31
import errno
32
32
import threading
33
33
 
34
 
import bzrlib
35
 
from bzrlib import (
 
34
import breezy
 
35
from breezy import (
36
36
    config,
37
37
    cleanup,
38
38
    cmdline,
46
46
    )
47
47
""")
48
48
 
49
 
from bzrlib.hooks import Hooks
50
 
from bzrlib.i18n import gettext
 
49
from breezy.hooks import Hooks
 
50
from breezy.i18n import gettext
51
51
# Compatibility - Option used to be in commands.
52
 
from bzrlib.option import Option
53
 
from bzrlib.plugin import disable_plugins, load_plugins
54
 
from bzrlib import registry
 
52
from breezy.option import Option
 
53
from breezy.plugin import disable_plugins, load_plugins
 
54
from breezy import registry
55
55
 
56
56
 
57
57
class CommandInfo(object):
165
165
    if builtin_command_registry.keys():
166
166
        # only load once
167
167
        return
168
 
    import bzrlib.builtins
169
 
    for cmd_class in _scan_module_for_commands(bzrlib.builtins).values():
 
168
    import breezy.builtins
 
169
    for cmd_class in _scan_module_for_commands(breezy.builtins).values():
170
170
        builtin_command_registry.register(cmd_class)
171
 
    bzrlib.builtins._register_lazy_builtins()
 
171
    breezy.builtins._register_lazy_builtins()
172
172
 
173
173
 
174
174
def _scan_module_for_commands(module):
309
309
    # Only do external command lookups when no command is found so far.
310
310
    if cmd_or_None is not None:
311
311
        return cmd_or_None
312
 
    from bzrlib.externalcommand import ExternalCommand
 
312
    from breezy.externalcommand import ExternalCommand
313
313
    cmd_obj = ExternalCommand.find_command(cmd_name)
314
314
    if cmd_obj:
315
315
        return cmd_obj
316
316
 
317
317
 
318
318
def _get_plugin_command(cmd_or_None, cmd_name):
319
 
    """Get a command from bzr's plugins."""
 
319
    """Get a command from brz's plugins."""
320
320
    try:
321
321
        return plugin_cmds.get(cmd_name)()
322
322
    except KeyError:
331
331
class Command(object):
332
332
    """Base class for commands.
333
333
 
334
 
    Commands are the heart of the command-line bzr interface.
 
334
    Commands are the heart of the command-line brz interface.
335
335
 
336
336
    The command object mostly handles the mapping of command-line
337
 
    parameters into one or more bzrlib operations, and of the results
 
337
    parameters into one or more breezy operations, and of the results
338
338
    into textual output.
339
339
 
340
340
    Commands normally don't have any state.  All their arguments are
385
385
 
386
386
    :cvar hooks: An instance of CommandHooks.
387
387
 
388
 
    :cvar __doc__: The help shown by 'bzr help command' for this command.
 
388
    :cvar __doc__: The help shown by 'brz help command' for this command.
389
389
        This is set by assigning explicitly to __doc__ so that -OO can
390
390
        be used::
391
391
 
434
434
 
435
435
        Only describes arguments, not options.
436
436
        """
437
 
        s = 'bzr ' + self.name() + ' '
 
437
        s = 'brz ' + self.name() + ' '
438
438
        for aname in self.takes_args:
439
439
            aname = aname.upper()
440
440
            if aname[-1] in ['$', '+']:
469
469
            # Note: If self.gettext() translates ':Usage:\n', the section will
470
470
            # be shown after "Description" section and we don't want to
471
471
            # translate the usage string.
472
 
            # Though, bzr export-pot don't exports :Usage: section and it must
 
472
            # Though, brz export-pot don't exports :Usage: section and it must
473
473
            # not be translated.
474
474
            doc = self.gettext(doc)
475
475
        else:
530
530
                        result += ':%s:\n%s\n' % (label, sections[label])
531
531
                result += '\n'
532
532
        else:
533
 
            result += (gettext("See bzr help %s for more details and examples.\n\n")
 
533
            result += (gettext("See brz help %s for more details and examples.\n\n")
534
534
                % self.name())
535
535
 
536
536
        # Add the aliases, source (plug-in) and see also links, if any
559
559
 
560
560
        # If this will be rendered as plain text, convert it
561
561
        if plain:
562
 
            import bzrlib.help_topics
563
 
            result = bzrlib.help_topics.help_as_plain_text(result)
 
562
            import breezy.help_topics
 
563
            result = breezy.help_topics.help_as_plain_text(result)
564
564
        return result
565
565
 
566
566
    @staticmethod
645
645
        self._setup_outf()
646
646
 
647
647
        # Process the standard options
648
 
        if 'help' in opts:  # e.g. bzr add --help
 
648
        if 'help' in opts:  # e.g. brz add --help
649
649
            self.outf.write(self.get_help_text())
650
650
            return 0
651
 
        if 'usage' in opts:  # e.g. bzr add --usage
 
651
        if 'usage' in opts:  # e.g. brz add --usage
652
652
            self.outf.write(self.get_help_text(verbose=False))
653
653
            return 0
654
654
        trace.set_verbosity_level(option._verbosity_level)
768
768
        These are all empty initially, because by default nothing should get
769
769
        notified.
770
770
        """
771
 
        Hooks.__init__(self, "bzrlib.commands", "Command.hooks")
 
771
        Hooks.__init__(self, "breezy.commands", "Command.hooks")
772
772
        self.add_hook('extend_command',
773
773
            "Called after creating a command object to allow modifications "
774
774
            "such as adding or removing options, docs etc. Called with the "
775
 
            "new bzrlib.commands.Command object.", (1, 13))
 
775
            "new breezy.commands.Command object.", (1, 13))
776
776
        self.add_hook('get_command',
777
777
            "Called when creating a single command. Called with "
778
778
            "(cmd_or_None, command_name). get_command should either return "
779
779
            "the cmd_or_None parameter, or a replacement Command object that "
780
780
            "should be used for the command. Note that the Command.hooks "
781
781
            "hooks are core infrastructure. Many users will prefer to use "
782
 
            "bzrlib.commands.register_command or plugin_cmds.register_lazy.",
 
782
            "breezy.commands.register_command or plugin_cmds.register_lazy.",
783
783
            (1, 17))
784
784
        self.add_hook('get_missing_command',
785
785
            "Called when creating a single command if no command could be "
878
878
    return argdict
879
879
 
880
880
def apply_coveraged(dirname, the_callable, *args, **kwargs):
881
 
    # Cannot use "import trace", as that would import bzrlib.trace instead of
 
881
    # Cannot use "import trace", as that would import breezy.trace instead of
882
882
    # the standard library's trace.
883
883
    trace = __import__('trace')
884
884
 
933
933
        # specially here, but hopefully they're handled ok by the logger now
934
934
        exc_info = sys.exc_info()
935
935
        exitcode = trace.report_exception(exc_info, sys.stderr)
936
 
        if os.environ.get('BZR_PDB'):
 
936
        if os.environ.get('BRZ_PDB'):
937
937
            print '**** entering debugger'
938
938
            import pdb
939
939
            pdb.post_mortem(exc_info[2])
941
941
 
942
942
 
943
943
def apply_lsprofiled(filename, the_callable, *args, **kwargs):
944
 
    from bzrlib.lsprof import profile
 
944
    from breezy.lsprof import profile
945
945
    ret, stats = profile(exception_to_return_code, the_callable,
946
946
                         *args, **kwargs)
947
947
    stats.sort()
964
964
        If it is unspecified, the global config will be used.
965
965
    """
966
966
    if config is None:
967
 
        import bzrlib.config
968
 
        config = bzrlib.config.GlobalConfig()
 
967
        import breezy.config
 
968
        config = breezy.config.GlobalConfig()
969
969
    alias = config.get_alias(cmd)
970
970
    if (alias):
971
971
        return cmdline.split(alias)
1013
1013
    --concurrency
1014
1014
        Specify the number of processes that can be run concurrently (selftest).
1015
1015
    """
1016
 
    trace.mutter("bazaar version: " + bzrlib.__version__)
 
1016
    trace.mutter("breezy version: " + breezy.__version__)
1017
1017
    argv = _specified_or_unicode_argv(argv)
1018
 
    trace.mutter("bzr arguments: %r", argv)
 
1018
    trace.mutter("brz arguments: %r", argv)
1019
1019
 
1020
1020
    opt_lsprof = opt_profile = opt_no_plugins = opt_builtin = \
1021
1021
            opt_no_l10n = opt_no_aliases = False
1047
1047
        elif a == '--builtin':
1048
1048
            opt_builtin = True
1049
1049
        elif a == '--concurrency':
1050
 
            os.environ['BZR_CONCURRENCY'] = argv[i + 1]
 
1050
            os.environ['BRZ_CONCURRENCY'] = argv[i + 1]
1051
1051
            i += 1
1052
1052
        elif a == '--coverage':
1053
1053
            opt_coverage_dir = argv[i + 1]
1062
1062
            argv_copy.append(a)
1063
1063
        i += 1
1064
1064
 
1065
 
    if bzrlib.global_state is None:
1066
 
        # FIXME: Workaround for users that imported bzrlib but didn't call
1067
 
        # bzrlib.initialize -- vila 2012-01-19
 
1065
    if breezy.global_state is None:
 
1066
        # FIXME: Workaround for users that imported breezy but didn't call
 
1067
        # breezy.initialize -- vila 2012-01-19
1068
1068
        cmdline_overrides = config.CommandLineStore()
1069
1069
    else:
1070
 
        cmdline_overrides = bzrlib.global_state.cmdline_overrides
 
1070
        cmdline_overrides = breezy.global_state.cmdline_overrides
1071
1071
    cmdline_overrides._from_cmdline(override_config)
1072
1072
 
1073
1073
    debug.set_debug_flags_from_config()
1191
1191
def main(argv=None):
1192
1192
    """Main entry point of command-line interface.
1193
1193
 
1194
 
    Typically `bzrlib.initialize` should be called first.
 
1194
    Typically `breezy.initialize` should be called first.
1195
1195
 
1196
1196
    :param argv: list of unicode command-line arguments similar to sys.argv.
1197
1197
        argv[0] is script name usually, it will be ignored.
1198
1198
        Don't pass here sys.argv because this list contains plain strings
1199
1199
        and not unicode; pass None instead.
1200
1200
 
1201
 
    :return: exit code of bzr command.
 
1201
    :return: exit code of brz command.
1202
1202
    """
1203
1203
    if argv is not None:
1204
1204
        argv = argv[1:]
1220
1220
 
1221
1221
 
1222
1222
def run_bzr_catch_user_errors(argv):
1223
 
    """Run bzr and report user errors, but let internal errors propagate.
 
1223
    """Run brz and report user errors, but let internal errors propagate.
1224
1224
 
1225
1225
    This is used for the test suite, and might be useful for other programs
1226
1226
    that want to wrap the commandline interface.