rbtools.commands¶
Base support for creating commands.
Functions
|
Determine if the given command exists. |
|
Return an entry point for the given rbtools command. |
Classes
|
Abstract base class for commands which offer subcommands. |
|
Abstract base class for a subcommand. |
|
Base class for rb commands. |
|
Output wrapper for JSON output. |
|
Filters log messages of a given level. |
|
Represents an option for a command. |
|
Represents a named group of options. |
|
Wrapper for output of a command. |
|
Smartly formats help text, preserving paragraphs. |
Exceptions
|
|
- exception rbtools.commands.ParseError[source]¶
Bases:
CommandError
- class rbtools.commands.JSONOutput(output_stream)[source]¶
Bases:
object
Output wrapper for JSON output.
JSON outputter class that stores Command outputs in python dictionary and outputs as JSON object to output stream object. Commands should add any structured output to this object. JSON output is then enabled with the –json argument.
New in version 3.0.
- __init__(output_stream)[source]¶
Initialize JSONOutput class.
- Parameters:
output_stream (
Object
) – Object to output JSON object to.
- append(key, value)[source]¶
Add new value to an existing list associated with key.
- Parameters:
- Raises:
KeyError – The key was not found in the state.
AttributeError – The existing value was not a list.
- add_error(error)[source]¶
Add new error to ‘errors’ key.
Append a new error to the
errors
key, creating one if needed.- Parameters:
error (
unicode
) – The error that will be added toerrors
.
- class rbtools.commands.SmartHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]¶
Bases:
HelpFormatter
Smartly formats help text, preserving paragraphs.
- class rbtools.commands.OutputWrapper(output_stream)[source]¶
Bases:
object
Wrapper for output of a command.
Wrapper around some output object that handles outputting messages. Child classes specify the default object. The wrapper can handle messages in either unicode or bytes.
New in version 3.0.
- __init__(output_stream)[source]¶
Initialize with an output object to stream to.
- Parameters:
output_stream (
object
) – The output stream to send command output to.
- class rbtools.commands.Option(*opts, **attrs)[source]¶
Bases:
object
Represents an option for a command.
The arguments to the constructor should be treated like those to argparse’s add_argument, with the exception that the keyword argument ‘config_key’ is also valid. If config_key is provided it will be used to retrieve the config value as a default if the option is not specified. This will take precedence over the default argument.
Serves as a wrapper around the ArgumentParser options, allowing us to specify defaults which will be grabbed from the configuration after it is loaded.
- class rbtools.commands.OptionGroup(name=None, description=None, option_list=[])[source]¶
Bases:
object
Represents a named group of options.
Each group has a name, an optional description, and a list of options. It serves as a way to organize related options, making it easier for users to scan for the options they want.
This works like argparse’s argument groups, but is designed to work with our special Option class.
- add_to(parser, config={}, argv=[])[source]¶
Add the group and all its contained options to the parser.
- Parameters:
parser (
argparse.ArgumentParser
) – The command-line parser.config (
dict
) – The loaded RBTools configuration.argv (
list
, deprecated) – Unused legacy argument.
- class rbtools.commands.LogLevelFilter(level)[source]¶
Bases:
Filter
Filters log messages of a given level.
Only log messages that have the specified level will be allowed by this filter. This prevents propagation of higher level types to lower log handlers.
- class rbtools.commands.Command(transport_cls=<class 'rbtools.api.transport.sync.SyncTransport'>, stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, stderr=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, stdin=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>)[source]¶
Bases:
object
Base class for rb commands.
This class will handle retrieving the configuration, and parsing command line options.
usage
is a list of usage strings each showing a use case. These should not include the main rbt command or the command name; they will be added automatically.- repository¶
The API resource corresponding to the repository.
- repository_info¶
The repository info object. This will be
None
ifneeds_scm_client
isFalse
.
- stdout¶
Standard unicode output wrapper that subclasses must write to.
- Type:
- stderr¶
Standard unicode error output wrapper that subclasses must write to.
- Type:
- stdin¶
Standard input.
New in version 3.1.
- Type:
- stdout_bytes¶
Standard byte output wrapper that subclasses must write to.
- Type:
- stderr_bytes¶
Standard byte error output wrapper that subclasses must write to.
- Type:
- tool¶
The SCM client. This will be
None
ifneeds_scm_client
isFalse
.- Type:
rbtools.clients.base.BaseSCMClient
- description = ''[source]¶
A short description of the command, suitable for display in usage text.
- Type:
- needs_api = False[source]¶
Whether the command needs the API client.
If this is set, the initialization of the command will set
api_client
andapi_root
.New in version 3.0.
- Type:
- needs_diffs = False[source]¶
Whether the command needs to generate diffs.
If this is set, the initialization of the command will check for the presence of a diff tool compatible with the chosen type of repository.
This depends on
needs_repository
andneeds_scm_client
both being set toTrue
.New in version 4.0.
- Type:
- needs_scm_client = False[source]¶
Whether the command needs the SCM client.
If this is set, the initialization of the command will set
repository_info
andtool
.New in version 3.0.
- Type:
- needs_repository = False[source]¶
Whether the command needs the remote repository object.
If this is set, the initialization of the command will set
repository
.New in version 3.0.
- Type:
- args = ''[source]¶
Usage text for what arguments the command takes.
Arguments for the command are anything passed in other than defined options (for example, revisions passed to rbt post).
- Type:
- option_list = [][source]¶
Command-line options for this command.
- Type:
list
ofOption
orOptionGroup
- default_transport_cls[source]¶
alias of
SyncTransport
- __init__(transport_cls=<class 'rbtools.api.transport.sync.SyncTransport'>, stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, stderr=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, stdin=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>)[source]¶
Initialize the base functionality for the command.
- Parameters:
transport_cls (
rbtools.api.transport.Transport
, optional) – The transport class used for all API communication. By default, this uses the transport defined indefault_transport_cls
.stdout (
io.TextIOWrapper
, optional) –The standard output stream. This can be used to capture output programmatically.
New in version 3.1.
stderr (
io.TextIOWrapper
, optional) –The standard error stream. This can be used to capture errors programmatically.
New in version 3.1.
stdin (
io.TextIOWrapper
, optional) –The standard input stream. This can be used to provide input programmatically.
New in version 3.1.
- initialize()[source]¶
Initialize the command.
This will set up various prerequisites for commands. Individual command subclasses can control what gets done by setting the various
needs_*
attributes (as documented in this class).
- create_arg_parser(argv)[source]¶
Create and return the argument parser.
- Parameters:
- Returns:
Argument parser for commandline arguments
- Return type:
- run_from_argv(argv)[source]¶
Execute the command using the provided arguments.
The options and commandline arguments will be parsed from
argv
and the commandsmain
method will be called.
- initialize_scm_tool(client_name=None, require_repository_info=True)[source]¶
Initialize the SCM tool for the current working directory.
- Parameters:
client_name (
unicode
, optional) – A specific client name, which can come from the configuration. This can be used to disambiguate if there are nested repositories, or to speed up detection.require_repository_info (
bool
, optional) – Whether information on a repository is required. This is the default. If disabled, this will returnNone
for the repository information if a matching repository could not be found.
- Returns:
A 2-tuple, containing the repository info structure and the tool instance.
- Return type:
- setup_tool(tool, api_root=None)[source]¶
Performs extra initialization on the tool.
If api_root is not provided we’ll assume we want to initialize the tool using only local information
- get_server_url(repository_info, tool)[source]¶
Return the Review Board server url.
- Parameters:
repository_info (
rbtools.clients.base.repository.RepositoryInfo
, optional) – Information about the current repositorytool (
rbtools.clients.base.BaseSCMClient
, optional) – The repository client.
- Returns:
The server URL.
- Return type:
- credentials_prompt(realm, uri, username=None, password=None, *args, **kwargs)[source]¶
Prompt the user for credentials using the command line.
This will prompt the user, and then return the provided username and password. This is used as a callback in the API when the user requires authorization.
- otp_token_prompt(uri, token_method, *args, **kwargs)[source]¶
Prompt the user for a one-time password token.
Their account is configured with two-factor authentication. The server will have sent a token to their configured mobile device or application. The user will be prompted for this token.
- get_api(server_url)[source]¶
Returns an RBClient instance and the associated root resource.
Commands should use this method to gain access to the API, instead of instantianting their own client.
- get_capabilities(api_root: RootResource) Capabilities [source]¶
Retrieve capabilities from the server and return them.
- Parameters:
api_root (
rbtools.api.resource.RootResource
) – The root resource- Returns:
The server capabilities.
- Return type:
- class rbtools.commands.BaseSubCommand(options, config, *args, **kwargs)[source]¶
Bases:
Command
Abstract base class for a subcommand.
- __init__(options, config, *args, **kwargs)[source]¶
Initialize the subcommand.
- Parameters:
options (
argparse.Namespace
) – The parsed options.config (
dict
) – The loaded RBTools configuration.*args (
list
) – Positional arguments to pass to the Command class.**kwargs (
dict
) – Keyword arguments to pass to the Command class.
- class rbtools.commands.BaseMultiCommand(transport_cls=<class 'rbtools.api.transport.sync.SyncTransport'>, stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, stderr=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, stdin=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>)[source]¶
Bases:
Command
Abstract base class for commands which offer subcommands.
Some commands (such as rbt review) want to offer many subcommands.
New in version 3.0.
- subcommands = {}[source]¶
The available subcommands.
This is a list of BaseSubCommand sub classes.
- Type: