diff -r 6b08429a3932 Lib/distutils/command/bdist_rpm.py --- a/Lib/distutils/command/bdist_rpm.py Mon Nov 30 03:18:29 2015 +0000 +++ b/Lib/distutils/command/bdist_rpm.py Mon Nov 30 11:56:05 2015 +0100 @@ -338,30 +338,19 @@ 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] + out = subprocess.check_output(q_cmd) + except (OSError, subprocess.CalledProcessError): + raise DistutilsExecError("Failed to execute: %r" % (q_cmd,)) - status = out.close() - if status: - raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) - - finally: - out.close() + lines = [line.split() for line in out.splitlines()] + assert(all(len(l) == 2 for l in lines)) + binary_rpms = [i for _, i in lines] + # The source rpm is named after the first entry in the spec file + source_rpm = lines[0][0] if lines else None self.spawn(rpm_cmd)