Combine mock stderr and stdout logs

Mock doesn't normally log anything to stdout - so it's confusing to mention
separate logs in the messages. Combine the two output streams together.
(This is what koji does as well.)
This commit is contained in:
Owen W. Taylor
2020-10-29 10:20:54 -04:00
parent cd5cf28ce2
commit debfd8a5c5
3 changed files with 17 additions and 24 deletions

View File

@@ -26,27 +26,24 @@ def find_srpm(cod):
return os.path.join(cod, f)
def execute_cmd(args, stdout=None, stderr=None, cwd=None):
def execute_cmd(args, output=None, cwd=None):
"""
Executes command defined by `args`. If `stdout` or `stderr` is set to
Python file object, the stderr/stdout output is redirecter to that file.
Executes command defined by `args`. If `output` is set to
Python file object, the stderr and stdout output is redirected to that file.
If `cwd` is set, current working directory is set accordingly for the
executed command.
:param args: list defining the command to execute.
:param stdout: Python file object to redirect the stdout to.
:param stderr: Python file object to redirect the stderr to.
:param output: Python file object to redirect the stderr and stdout to.
:param cwd: string defining the current working directory for command.
:raises RuntimeError: Raised when command exits with non-zero exit code.
"""
out_log_msg = ""
if stdout and hasattr(stdout, "name"):
out_log_msg += ", stdout log: %s" % stdout.name
if stderr and hasattr(stderr, "name"):
out_log_msg += ", stderr log: %s" % stderr.name
if output and hasattr(output, "name"):
out_log_msg += ", output log: %s" % output.name
log.info("Executing the command \"%s\"%s" % (" ".join(args), out_log_msg))
proc = subprocess.Popen(args, stdout=stdout, stderr=stderr, cwd=cwd)
proc = subprocess.Popen(args, stdout=output, stderr=output, cwd=cwd)
out, err = proc.communicate()
if proc.returncode != 0: