Tools for running external processes.
Functions
level2tag(level) |
Classes
BaseOutputHandler([logger]) | Base class for output handlers |
BaseToolController([logger]) | Base class for controlling command line tools. |
StringIO | Text I/O implementation using an in-memory buffer. |
ToolDescriptor(executable[, args, cwd, env, ...]) | Command line tool desctiptor. |
Bases: object
Base class for output handlers
Feed some data to the parser.
It is processed insofar as it consists of complete elements; incomplete data is buffered until more data is fed or close() is called.
Handle output lines.
This method is not meant to be directly called by the user.
The user, anyway, can provide a custom implementation in derived classes.
Parameters: | data – an entire output line (including the trailing “end of line” character. |
---|
Handle progress data.
This method is not meant to be called by the user.
The user, anyway, can provide a custom implementation in derived classes.
Parameters: | data – a list containing an item for each named group in the “progress” regular expression: (pulse, percentage, text) for the default implementation. Each item can be None. |
---|
Bases: object
Base class for controlling command line tools.
A tool controller runs an external tool in controlled way. The output of the child process is handled by the controller and, optionally, notifications can be achieved at sub-process termination.
A tool controller also allows to stop the controlled process.
Note
after the process termination the user can still query both subprocess and stopped for getting info about the executed process.
The user should have care of calling reset() when info n executed process are no more needed or before executing a new process.
Hook method for extra finalization tasks.
This method is always called after finalization and before controller reset.
The user can provide a custom implementation in derived classes in order to perform extra finalization actions.
This method is not meant to be called from the user.
Hook method for extra pre-run actions.
This method is always called before the controlled subprocess is actually started. The user can provide its own custom implementation in derived classes in order to perform additional actions.
This method is not meant to be called from the user.
the subprocess instance
Bases: object
Command line tool desctiptor.
A ToolDescriptor instance describes a command line tool (executable), how to run it (args, cwd, env) and how to handle its output (stdout_handler, stderr_handler).
Example:
handler = BaseOutputHandler()
ll = ToolDescriptor(executable='ls', args=['-l'],
stdout_handler=handler)
controller.run_tool(ll)
# In this case no executabe is set in the descriptor.
cmd = ToolDescriptor(stdout_handler=handler)
# The executable name is passed at execution time (first argument)
controller.run_tool(cmd, 'ls', '-l')
Parameters: |
|
---|
See also
default args for command
Generate the complete command-line for the tool.
This method is meant to be used together with “subprocess” so the “comman-line” actually is a list of strings.
If the executable attribute is not set (evaluate false) then the first non-keyword argument is considered to be the executable tool name.
The command line is build as follows:
executable keyword-arguments args
If you need a command-line in single string form use something like:
' '.join(tool.cmdline(arg1, arg2, arg3))
program working directory
the tool environment
if set to True (default) then the env dictionaty is used to update the system environment
full path of the tool executable or just the tool program name
output encoding, it is used to decode the subprocess ouput
is set to true the external too is executed in a system shell
Warning
some implementation don’t allow to stop a subprocess executed via shell
the OutputHandler for the stderr of the tool
the OutputHandler for the stdout of the tool
See also