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.

__enter__(self)[source]
set_stdout(self)[source]
set_stderr(self)[source]
__exit__(self, *args)[source]
property out(self)

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

property err(self)

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

cleanup(self)[source]

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

class buildtest.utils.command.BuildTestCommand(cmd=None)[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, optional) – Input shell command

set_command(self, cmd)[source]

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.

execute(self, timeout=None)[source]

Execute a system command and return output and error.

returncode(self)[source]

Returns the return code from shell command

Returns

returncode of shell command

Return type

int

decode(self, line)[source]

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

get_output(self)[source]

Returns the output content from shell command

get_error(self)[source]

Returns the error content from shell command

get_command(self)[source]

Returns the executed command