buildtest.utils.command
¶
Module Contents¶
Classes¶
Class method to invoke shell commands and retrieve output and error. |
|
capture output from stdout and stderr into capture object. |
- class buildtest.utils.command.BuildTestCommand(cmd=None)¶
Class method to invoke shell commands and retrieve output and error. This class is inspired and derived from utils functions in https://github.com/vsoch/scif
- decode(self, line)¶
Given a line of output (error or regular) decode using the system default, if appropriate
- execute(self)¶
Execute a system command and return output and error. :param cmd: shell command to execute :type cmd: str, required :return: Output and Error from shell command :rtype: two str objects
- get_command(self)¶
Returns the executed command :rtype: str
- get_error(self)¶
Returns the error from shell command :rtype: str
- get_output(self)¶
Returns the output from shell command :rtype: str
- returncode(self)¶
Returns the return code from shell command :rtype: int
- set_command(self, cmd)¶
parse is called when a new command is provided to ensure we have a list. We don’t check that the executable is on the path, as the initialization might not occur in the runtime environment.
- class buildtest.utils.command.Capturing¶
capture output from stdout and stderr into capture object. This is based off of github.com/vsoch/gridtest but modified to write files. The stderr and stdout are set to temporary files at the init of the capture, and then they are closed when we exit. This means expected usage looks like:
- with Capturing() as capture:
process = subprocess.Popen(…)
And then the output and error are retrieved from reading the files: and exposed as properties to the client:
capture.out capture.err
And cleanup means deleting these files, if they exist.
- __enter__(self)¶
- __exit__(self, *args)¶
- cleanup(self)¶
- property err(self)¶
Return error stream. Returns empty string if empty or doesn’t exist. Returns (str) : error stream written to file
- property out(self)¶
Return output stream. Returns empty string if empty or doesn’t exist. Returns (str) : output stream written to file
- set_stderr(self)¶
- set_stdout(self)¶