buildtest.utils.command

Module Contents

Classes

Capturing

capture output from stdout and stderr into capture object.

BuildTestCommand

Class method to invoke shell commands and retrieve output and error.

class buildtest.utils.command.Capturing[source]

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.

property out

Return content of output stream if file exists otherwise returns empty string

property err

Return content of error stream if file exists otherwise returns empty string.

__enter__()[source]
set_stdout()[source]
set_stderr()[source]
__exit__(*args)[source]
cleanup()[source]

This method will remove stdout and stderr file upon reading both streams

class buildtest.utils.command.BuildTestCommand(cmd)[source]

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

The initializer method will initialize class variables and check input argument cmd and make sure command is in a list format.

Parameters:

cmd (str) – Input shell command

execute(timeout=None)[source]

Execute a system command and return output and error.

Parameters:

timeout (int, optional) – The timeout value in number of seconds for a process. This argument is passed to Popen.communicate

returncode()[source]

Returns the return code from shell command

Returns:

returncode of shell command

Return type:

int

decode(line)[source]

Given a line of output (error or regular) decode using the system default, if appropriate

get_output()[source]

Returns the output content from shell command

get_error()[source]

Returns the error content from shell command

get_command()[source]

Returns the executed command