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]
<BLANKLINE>
Options:
  -h, --help  Print a help message.
<BLANKLINE>
  --complete  Print a list of possible completions.
<BLANKLINE>
A detailed help message.

Methods

cleanup
complete
help
run
usage
cleanup()
complete(argument=None, fragment=None)
help(*args)
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
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
format_description
format_epilog
format_heading
format_option
format_option_strings
format_usage
indent
option_help
set_long_opt_delimiter
set_parser
set_short_opt_delimiter
store_option_strings
option_help()
class libbe.command.base.StdInputOutput(input_encoding=None, output_encoding=None)

Methods

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

Methods

cleanup
get_bugdir
get_storage
get_unconnected_storage
set_bugdir
set_storage
set_unconnected_storage
setup_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
setup_command
get_stdout()
set_stdin(stdin_string)
class libbe.command.base.UnconnectedStorageGetter(location)
exception libbe.command.base.UnknownCommand(command_name, message=None)
exception libbe.command.base.UsageError(command=None, command_name=None, message=None)

A serious parsing error due to invalid BE command construction.

The distinction between UserErrors and the more specific UsageErrors is that when displaying a UsageError to the user, the user is pointed towards the command usage information. Use the more general UserError if you feel that usage information would not be particularly enlightening.

exception libbe.command.base.UserError

An error due to improper BE usage.

class libbe.command.base.UserInterface(io=None, location=None)

Methods

cleanup
help
run
setup_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'
(No module named 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