xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/utils/subprocesstweak.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#
2*4882a593Smuzhiyun# SPDX-License-Identifier: MIT
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyunimport subprocess
5*4882a593Smuzhiyun
6*4882a593Smuzhiyunclass OETestCalledProcessError(subprocess.CalledProcessError):
7*4882a593Smuzhiyun    def __str__(self):
8*4882a593Smuzhiyun        def strify(o):
9*4882a593Smuzhiyun            if isinstance(o, bytes):
10*4882a593Smuzhiyun                return o.decode("utf-8", errors="replace")
11*4882a593Smuzhiyun            else:
12*4882a593Smuzhiyun                return o
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun        s = "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
15*4882a593Smuzhiyun        if hasattr(self, "output") and self.output:
16*4882a593Smuzhiyun            s = s + "\nStandard Output: " + strify(self.output)
17*4882a593Smuzhiyun        if hasattr(self, "stderr") and self.stderr:
18*4882a593Smuzhiyun            s = s + "\nStandard Error: " + strify(self.stderr)
19*4882a593Smuzhiyun        return s
20*4882a593Smuzhiyun
21*4882a593Smuzhiyundef errors_have_output():
22*4882a593Smuzhiyun    subprocess.CalledProcessError = OETestCalledProcessError
23