command - Wrap complex commands in Python objects
Tools to wrap a Python API around interactive and non-interactive programs.
The command.Command and interpreter.Interpreter classes are meant to be derived from in order to
handle batch and interactive commands respectively. They can be provided with option.Config
instances which describe the options available to the programs being wrapped. The option.Parser
class can then be used to validate option sets and construct the corresponding command lines.
See the svn.svn module for a concrete example.
command - Drive batch commands with function calls
Non interactive command driver.
-
class Command(cmd, debug=False)[source]
Represents the command to be executed.
Typically you would derive from this class and provide a different method for each alternative
way of invoking the program. If the program you want to execute has many sub-commands you
might provide a different method for each sub-command. You can use the option.Config class to
declare the options supported by your command and then use the config.Parser class to validate
your methods’ arguments and generate the resulting command line. A debug mode is available
in which commands are echoed rather than run. This can be enabled globally or separately for
each invocation.
-
run(parser, debug=False)[source]
Executes the command.
Takes as arguments a command line parser (see the option module) and a boolean indicating
whether debug mode should be used for this execution.
-
exception Error(cmd, returncode, err)[source]
Raised when command execution fails.
error - The command package exception hierarchy
Exception classes for the nxpy.command package.
-
exception BadLogFormat[source]
Raised if the requested formatting option is unknown
-
exception Error[source]
Package exceptions’ base class
-
exception ExpectError[source]
Raised on invalid input from stdout or stderr
-
exception TimeoutError[source]
Raised when expect didn’t satisfy a timing constraint
-
exception TimerError[source]
Raised on misuse of the Timer class
interpreter - Wrap interactive programs in Python classes
Interactive program driver.
-
exception BadCommand(cmd, err)[source]
Raised on a command execution failure
-
class BaseInterpreter(popen)[source]
Controls the execution of an interactive program in a sub-process.
Provides means to send input to the controlled process and to check different conditions on its
output and error streams.
-
class Interpreter(cmd)[source]
The actual Interpreter class.
Optionally accepts an alternative ‘subprocess’ implementation.
-
class Timer(timeout, retries, interval=0.1, quantum=0.01)[source]
A collaborative timer class
option - Describe complex command lines
Function argument to command line option conversion.
Provides means to describe commands with complicated syntaxes, which often combine sub-commands,
options and arguments. Typical examples include subversion and ftp.
-
class Config(prefix='--', separator=' ', bool_opts=(), value_opts=(), iterable_opts=(), format_opts={}, mapped_opts={}, opposite_opts={})[source]
Command option definitions.
Provides a single definition point for all the options supported by a command.
-
exception InvalidOptionError[source]
Raised when an option is not supported.
-
class Parser(config, command, arguments, options, **defaults)[source]
Constructs a complex command line from the provided ‘command’ and its ‘options’ and
‘arguments’. Uses a Config instance, ‘config’, to provide means to check conditions on the
supplied options.