diff -r 2e889344436e Lib/distutils/command/bdist_rpm.py --- a/Lib/distutils/command/bdist_rpm.py Sat Nov 28 22:38:24 2015 +0000 +++ b/Lib/distutils/command/bdist_rpm.py Sun Nov 29 13:41:39 2015 +0100 @@ -338,30 +338,22 @@ nvr_string = "%{name}-%{version}-%{release}" src_rpm = nvr_string + ".src.rpm" non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm" - q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % ( - src_rpm, non_src_rpm, spec_path) + q_cmd = ("rpm", "-q", "--qf", r"%s %s\n" % (src_rpm, non_src_rpm), + "--specfile", spec_path) - out = os.popen(q_cmd) try: - binary_rpms = [] - source_rpm = None - while True: - line = out.readline() - if not line: - break - l = line.strip().split() - assert(len(l) == 2) - binary_rpms.append(l[1]) - # The source rpm is named after the first entry in the spec file - if source_rpm is None: - source_rpm = l[0] + proc = subprocess.Popen(q_cmd, stdout=subprocess.PIPE) + except OSError: + raise DistutilsExecError("Failed to execute: %r" % (q_cmd,)) from None - status = out.close() - if status: - raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) - - finally: - out.close() + out, _ = proc.communicate() + lines = [line.split() for line in out] + assert(all(len(l) == 2 for l in lines)) + binary_rpms = [i for _, i in lines] + source_rpm = lines[0][0] + proc.stdout.close() + if proc.returncode: + raise DistutilsExecError("Failed to execute: %r" % (q_cmd,)) self.spawn(rpm_cmd)