Tools to wrap a Python API around interactive and non-interactive programs.
The command.Command and interpreter.Interpreter classes 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.
Non interactive command driver.
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 option.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.
Exception classes for the nxpy.command package.
Interactive program driver.
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.
Creates an interpreter instance. popen is a Popen-like object which must support non-blocking I/O.
Express expectations on the outcome of a command.
cond is a two argument callable which will be passed the command’s standard output and standard error, and which should return True if the expectation is satisfied. For the other arguments see the documentation for the Timer class.
Expect to find a match for the regexp regular expression within the where stream.
Executes the command and waits for the expected outcome or an error.
The actual Interpreter class.
This implementation uses a core.async_subprocess.AsyncPopen instance.
Wait for a match to a given regexp, passed either compiled or as a string.
A collaborative timer class. Support a polling mechanism by keeping track of the amount of time to wait before the next attempt, according to different policies.
Specify an overall timeout, a number of retries and/or an interval between them. The next attempt will not take place before a quantum has passed. Timings are expressed in seconds. If a timeout is specified it will take precedence over the other arguments; in that case the number of retries will take precedence over the interval. If neither a timeout nor a number of retries are specified the overall timer will never expire.
Indicate whether the current timer expired. Use as polling loop control condition.
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.
Command option definitions. Provides a single definition point for all the options supported by a command.
Constructor. Its arguments are used to specify all the valid options. Each option is prefixed by prefix. When an option takes multiple arguments these are separated by a separator. bool_opts must be specified on the command line when they are True. value_opts take a single argument; iterable_opts take multiple arguments; format_opts have their syntax specified by means of a format string; mapped_opts require some form of translation, usually because they are not valid Python identifiers; opposite_opts must be specified on the command line when they are False.
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. Other constraints on how options should be used may be expressed and verified by means of the check methods.
Takes an instance of Config, a command to execute, an iterable of arguments and a mapping of options and their actual values. The remaining keyword arguments indicate the options supported by command with their default values.
Checks that one and only one in a set of mutually exclusive options has been specified.
Checks that at most one in a set of mutually exclusive options has been specified.
Checks that options incompatible with arguments haven’t been specified if any argument is present.