-__all__ = ["PapiExecutor", "PapiResponse"]
-
-
-class PapiResponse(object):
- """Class for metadata specifying the Papi reply, stdout, stderr and return
- code.
- """
-
- def __init__(self, papi_reply=None, stdout="", stderr="", ret_code=None,
- requests=None):
- """Construct the Papi response by setting the values needed.
-
- :param papi_reply: API reply from last executed PAPI command(s).
- :param stdout: stdout from last executed PAPI command(s).
- :param stderr: stderr from last executed PAPI command(s).
- :param ret_code: ret_code from last executed PAPI command(s).
- :param requests: List of used PAPI requests. It is used while verifying
- replies. If None, expected replies must be provided for verify_reply
- and verify_replies methods.
- :type papi_reply: list
- :type stdout: str
- :type stderr: str
- :type ret_code: int
- :type requests: list
- """
-
- # API reply from last executed PAPI command(s).
- self.reply = papi_reply
-
- # stdout from last executed PAPI command(s).
- self.stdout = stdout
-
- # stderr from last executed PAPI command(s).
- self.stderr = stderr
-
- # return code from last executed PAPI command(s).
- self.ret_code = ret_code
-
- # List of used PAPI requests.
- self.requests = requests
-
- # List of expected PAPI replies. It is used while verifying replies.
- if self.requests:
- self.expected_replies = \
- ["{rqst}_reply".format(rqst=rqst) for rqst in self.requests]
-
- def __str__(self):
- """Return string with human readable description of the PapiResponse.
-
- :returns: Readable description.
- :rtype: str
- """
- return ("papi_reply={papi_reply},"
- "stdout={stdout},"
- "stderr={stderr},"
- "ret_code={ret_code},"
- "requests={requests}".
- format(papi_reply=self.reply,
- stdout=self.stdout,
- stderr=self.stderr,
- ret_code=self.ret_code,
- requests=self.requests))
-
- def __repr__(self):
- """Return string executable as Python constructor call.
-
- :returns: Executable constructor call.
- :rtype: str
- """
- return "PapiResponse({str})".format(str=str(self))
-
- def verify_reply(self, cmd_reply=None, idx=0,
- err_msg="Failed to verify PAPI reply."):
- """Verify and return data from the PAPI response.
-
- Note: Use only with a simple request / reply command. In this case the
- PAPI reply includes 'retval' which is checked in this method.
-
- Use if PAPI response includes only one command reply.