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
57
57
class CommandInfo(object):
165
165
if builtin_command_registry.keys():
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()
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)
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."""
321
321
return plugin_cmds.get(cmd_name)()
331
331
class Command(object):
332
332
"""Base class for commands.
334
Commands are the heart of the command-line bzr interface.
334
Commands are the heart of the command-line brz interface.
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.
340
340
Commands normally don't have any state. All their arguments are
386
386
:cvar hooks: An instance of CommandHooks.
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
435
435
Only describes arguments, not options.
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)
530
530
result += ':%s:\n%s\n' % (label, sections[label])
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")
536
536
# Add the aliases, source (plug-in) and see also links, if any
560
560
# If this will be rendered as plain text, convert it
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)
645
645
self._setup_outf()
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())
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))
654
654
trace.set_verbosity_level(option._verbosity_level)
768
768
These are all empty initially, because by default nothing should get
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.",
784
784
self.add_hook('get_missing_command',
785
785
"Called when creating a single command if no command could be "
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')
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'
939
939
pdb.post_mortem(exc_info[2])
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,
964
964
If it is unspecified, the global config will be used.
966
966
if config is None:
968
config = bzrlib.config.GlobalConfig()
968
config = breezy.config.GlobalConfig()
969
969
alias = config.get_alias(cmd)
971
971
return cmdline.split(alias)
1014
1014
Specify the number of processes that can be run concurrently (selftest).
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)
1020
1020
opt_lsprof = opt_profile = opt_no_plugins = opt_builtin = \
1021
1021
opt_no_l10n = opt_no_aliases = False
1062
1062
argv_copy.append(a)
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()
1070
cmdline_overrides = bzrlib.global_state.cmdline_overrides
1070
cmdline_overrides = breezy.global_state.cmdline_overrides
1071
1071
cmdline_overrides._from_cmdline(override_config)
1073
1073
debug.set_debug_flags_from_config()
1191
1191
def main(argv=None):
1192
1192
"""Main entry point of command-line interface.
1194
Typically `bzrlib.initialize` should be called first.
1194
Typically `breezy.initialize` should be called first.
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.
1201
:return: exit code of bzr command.
1201
:return: exit code of brz command.
1203
1203
if argv is not None:
1204
1204
argv = argv[1:]
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.
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.