:py:mod:`buildtest.utils.command` ================================= .. py:module:: buildtest.utils.command Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: buildtest.utils.command.Capturing buildtest.utils.command.BuildTestCommand Attributes ~~~~~~~~~~ .. autoapisummary:: buildtest.utils.command.logger .. py:data:: logger .. py:class:: 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: .. code-block:: python 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. .. py:property:: out Return content of output stream if file exists otherwise returns empty string .. py:property:: err Return content of error stream if file exists otherwise returns empty string. .. py:method:: __enter__() .. py:method:: set_stdout() .. py:method:: set_stderr() .. py:method:: __exit__(*args) .. py:method:: cleanup() This method will remove stdout and stderr file upon reading both streams .. py:class:: BuildTestCommand(cmd) 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. :param cmd: Input shell command :type cmd: str .. py:method:: execute(timeout=None) Execute a system command and return output and error. :param timeout: The timeout value in number of seconds for a process. This argument is passed to `Popen.communicate `_ :type timeout: int, optional .. py:method:: reset_output() Reset output and error content .. py:method:: find_executable() Find the executable for the command. .. py:method:: decode_output(output) Decode the output to avoid UTF-8 decode error. .. py:method:: returncode() Returns the return code from shell command :returns: returncode of shell command :rtype: int .. py:method:: decode(line) Given a line of output (error or regular) decode using the system default, if appropriate .. py:method:: get_output() Returns the output content from shell command .. py:method:: get_error() Returns the error content from shell command .. py:method:: get_command() Returns the executed command