def collect_command_names(self): """Collect names of available bzr commands.""" from bzrlib import commands as _mod_commands names = list(_mod_commands.all_command_names()) self.cmds_dict = dict( (n, _mod_commands.get_cmd_object(n)) for n in names) # Find the commands for each category, public or otherwise builtins = _mod_commands.builtin_command_names() self.all_cmds = {'All': []} self.public_cmds = {'All': []} for name, cmd in self.cmds_dict.iteritems(): # If a command is builtin, we always put it into the Core # category, even if overridden in a plugin if name in builtins: category = 'Core' else: category = cmd.plugin_name() self.all_cmds['All'].append(name) self.all_cmds.setdefault(category, []).append(name) if not cmd.hidden: self.public_cmds['All'].append(name) self.public_cmds.setdefault(category, []).append(name) # Sort them for category in self.all_cmds: self.all_cmds[category].sort() try: self.public_cmds[category].sort() except KeyError: # no public commands - that's ok pass
def _help_commands_to_text(topic): """Generate the help text for the list of commands""" out = [] if topic == 'hidden-commands': hidden = True else: hidden = False names = set(_mod_commands.builtin_command_names()) # to eliminate duplicates names.update(_mod_commands.plugin_command_names()) commands = ((n, _mod_commands.get_cmd_object(n)) for n in names) shown_commands = [(n, o) for n, o in commands if o.hidden == hidden] max_name = max(len(n) for n, o in shown_commands) indent = ' ' * (max_name + 1) width = osutils.terminal_width() - 1 for cmd_name, cmd_object in sorted(shown_commands): plugin_name = cmd_object.plugin_name() if plugin_name is None: plugin_name = '' else: plugin_name = ' [%s]' % plugin_name cmd_help = cmd_object.help() if cmd_help: firstline = cmd_help.split('\n', 1)[0] else: firstline = '' helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name) lines = textwrap.wrap(helpstring, subsequent_indent=indent, width=width) for line in lines: out.append(line + '\n') return ''.join(out)
def _help_commands_to_text(topic): """Generate the help text for the list of commands""" out = [] if topic == 'hidden-commands': hidden = True else: hidden = False names = set( _mod_commands.builtin_command_names()) # to eliminate duplicates names.update(_mod_commands.plugin_command_names()) commands = ((n, _mod_commands.get_cmd_object(n)) for n in names) shown_commands = [(n, o) for n, o in commands if o.hidden == hidden] max_name = max(len(n) for n, o in shown_commands) indent = ' ' * (max_name + 1) width = osutils.terminal_width() - 1 for cmd_name, cmd_object in sorted(shown_commands): plugin_name = cmd_object.plugin_name() if plugin_name is None: plugin_name = '' else: plugin_name = ' [%s]' % plugin_name cmd_help = cmd_object.help() if cmd_help: firstline = cmd_help.split('\n', 1)[0] else: firstline = '' helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name) lines = textwrap.wrap(helpstring, subsequent_indent=indent, width=width) for line in lines: out.append(line + '\n') return ''.join(out)
def get_builtin_command_options(self): g = [] commands.install_bzr_command_hooks() for cmd_name in sorted(commands.builtin_command_names()): cmd = commands.get_cmd_object(cmd_name) for opt_name, opt in sorted(cmd.options().items()): g.append((cmd_name, opt)) self.assertTrue(g) return g
def get_builtin_command_options(self): g = [] commands.install_bzr_command_hooks() for cmd_name in sorted(commands.builtin_command_names()): cmd = commands.get_cmd_object(cmd_name) for opt_name, opt in sorted(cmd.options().items()): g.append((cmd_name, opt)) self.assert_(g) return g
def _command_helps(exporter, plugin_name=None): """Extract docstrings from path. This respects the Bazaar cmdtable/table convention and will only extract docstrings from functions mentioned in these tables. """ from glob import glob # builtin commands for cmd_name in _mod_commands.builtin_command_names(): command = _mod_commands.get_cmd_object(cmd_name, False) if command.hidden: continue if plugin_name is not None: # only export builtins if we are not exporting plugin commands continue note(gettext("Exporting messages from builtin command: %s"), cmd_name) _write_command_help(exporter, command) plugin_path = plugin.get_core_plugin_path() core_plugins = glob(plugin_path + '/*/__init__.py') core_plugins = [os.path.basename(os.path.dirname(p)) for p in core_plugins] # plugins for cmd_name in _mod_commands.plugin_command_names(): command = _mod_commands.get_cmd_object(cmd_name, False) if command.hidden: continue if plugin_name is not None and command.plugin_name() != plugin_name: # if we are exporting plugin commands, skip plugins we have not specified. continue if plugin_name is None and command.plugin_name() not in core_plugins: # skip non-core plugins # TODO: Support extracting from third party plugins. continue note( gettext( "Exporting messages from plugin command: {0} in {1}").format( cmd_name, command.plugin_name())) _write_command_help(exporter, command)
def _command_helps(exporter, plugin_name=None): """Extract docstrings from path. This respects the Bazaar cmdtable/table convention and will only extract docstrings from functions mentioned in these tables. """ from glob import glob # builtin commands for cmd_name in _mod_commands.builtin_command_names(): command = _mod_commands.get_cmd_object(cmd_name, False) if command.hidden: continue if plugin_name is not None: # only export builtins if we are not exporting plugin commands continue note(gettext("Exporting messages from builtin command: %s"), cmd_name) _write_command_help(exporter, command) plugin_path = plugin.get_core_plugin_path() core_plugins = glob(plugin_path + '/*/__init__.py') core_plugins = [os.path.basename(os.path.dirname(p)) for p in core_plugins] # plugins for cmd_name in _mod_commands.plugin_command_names(): command = _mod_commands.get_cmd_object(cmd_name, False) if command.hidden: continue if plugin_name is not None and command.plugin_name() != plugin_name: # if we are exporting plugin commands, skip plugins we have not specified. continue if plugin_name is None and command.plugin_name() not in core_plugins: # skip non-core plugins # TODO: Support extracting from third party plugins. continue note(gettext("Exporting messages from plugin command: {0} in {1}").format( cmd_name, command.plugin_name() )) _write_command_help(exporter, command)