libbe.command.base

class libbe.command.base.Argument(metavar=None, default=None, type='string', optional=False, repeatable=False, completion_callback=None, *args, **kwargs)
class libbe.command.base.Command(ui=None)

One-line command description here.

>>> c = Command()
>>> print c.help()
usage: be command [options]

Options:
  -h, --help  Print a help message.

  --complete  Print a list of possible completions.

A detailed help message.

Methods

cleanup()
complete([argument, fragment])
help(*args)
run([options, args])
usage()
cleanup()
complete(argument=None, fragment=None)
help(*args)
name = 'command'
run(options=None, args=None)
usage()
class libbe.command.base.CommandInput(name, help='')
class libbe.command.base.InputOutput(stdin=None, stdout=None)

Methods

cleanup()
setup_command(command)
cleanup()
setup_command(command)
class libbe.command.base.Option(callback=None, short_name=None, arg=None, *args, **kwargs)

Methods

validate()
validate()
class libbe.command.base.OptionFormatter(command)

Methods

dedent()
expand_default(option)
format_description(description)
format_epilog(epilog)
format_heading(heading)
format_option(option)
format_option_strings(option) Return a comma-separated list of option strings & metavariables.
format_usage(usage)
indent()
option_help()
set_long_opt_delimiter(delim)
set_parser(parser)
set_short_opt_delimiter(delim)
store_option_strings(parser)
option_help()
class libbe.command.base.StdInputOutput(input_encoding=None, output_encoding=None)

Methods

cleanup()
setup_command(command)
class libbe.command.base.StorageCallbacks(location=None)

Methods

cleanup()
get_bugdir() Callback for use by commands that need it.
get_storage() Callback for use by commands that need it.
get_unconnected_storage() Callback for use by commands that need it.
set_bugdir(bugdir)
set_storage(storage)
set_unconnected_storage(unconnected_storage)
setup_command(command)
cleanup()
get_bugdir()

Callback for use by commands that need it.

get_storage()

Callback for use by commands that need it.

get_unconnected_storage()

Callback for use by commands that need it.

The returned Storage instance is may actually be connected, but commands that make use of the returned value should only make use of non-connected Storage methods. This is mainly intended for the init command, which calls Storage.init().

set_bugdir(bugdir)
set_storage(storage)
set_unconnected_storage(unconnected_storage)
setup_command(command)
class libbe.command.base.StringInputOutput
>>> s = StringInputOutput()
>>> s.set_stdin('hello')
>>> s.stdin.read()
'hello'
>>> s.stdin.read()
''
>>> print >> s.stdout, 'goodbye'
>>> s.get_stdout()
'goodbye\n'
>>> s.get_stdout()
''

Also works with unicode strings

>>> s.set_stdin(u'hello')
>>> s.stdin.read()
u'hello'
>>> print >> s.stdout, u'goodbye'
>>> s.get_stdout()
u'goodbye\n'

Methods

cleanup()
get_stdout()
set_stdin(stdin_string)
setup_command(command)
get_stdout()
set_stdin(stdin_string)
class libbe.command.base.UnconnectedStorageGetter(location)
exception libbe.command.base.UnknownCommand(cmd)
exception libbe.command.base.UserError
class libbe.command.base.UserInterface(io=None, location=None)

Methods

cleanup()
help()
run(command[, options, args])
setup_command(command)
cleanup()
help()
run(command, options=None, args=None)
setup_command(command)
libbe.command.base.commands(command_names=False)
libbe.command.base.get_command(command_name)

Retrieves the module for a user command

>>> try:
...     get_command('asdf')
... except UnknownCommand, e:
...     print e
Unknown command 'asdf'
>>> repr(get_command('list')).startswith("<module 'libbe.command.list' from ")
True
libbe.command.base.get_command_class(module=None, command_name=None)

Retrieves a command class from a module.

>>> import_xml_mod = get_command('import-xml')
>>> import_xml = get_command_class(import_xml_mod, 'import-xml')
>>> repr(import_xml)
"<class 'libbe.command.import_xml.Import_XML'>"
>>> import_xml = get_command_class(command_name='import-xml')
>>> repr(import_xml)
"<class 'libbe.command.import_xml.Import_XML'>"
libbe.command.base.modname_to_command_name(modname)

Little hack to replicate >>> import sys >>> def real_modname_to_command_name(modname): ... mod = libbe.util.plugin.import_by_name( ... ‘libbe.command.%s’ % modname) ... attrs = [getattr(mod, name) for name in dir(mod)] ... commands = [] ... for attr_name in dir(mod): ... attr = getattr(mod, attr_name) ... try: ... if issubclass(attr, Command): ... commands.append(attr) ... except TypeError, e: ... pass ... if len(commands) == 0: ... raise Exception(‘No Command classes in %s’ % dir(mod)) ... return commands[0].name >>> real_modname_to_command_name(‘new’) ‘new’ >>> real_modname_to_command_name(‘import_xml’) ‘import-xml’

This Page