60b7a5f
--- Python-2.5a2/Lib/distutils/command/bdist_rpm.py.bdist-rpm	2005-04-15 02:17:20.000000000 -0400
60b7a5f
+++ Python-2.5a2/Lib/distutils/command/bdist_rpm.py	2006-06-19 09:14:28.000000000 -0400
60b7a5f
@@ -337,37 +337,47 @@
60b7a5f
         if not self.keep_temp:
60b7a5f
             rpm_cmd.append('--clean')
60b7a5f
         rpm_cmd.append(spec_path)
60b7a5f
+        # Determine the binary rpm names that should be built out of this spec
60b7a5f
+        # file
60b7a5f
+        # Note that some of these may not be really built (if the file
60b7a5f
+        # list is empty)
60b7a5f
+        nvr_string = "%{name}-%{version}-%{release}"
60b7a5f
+        src_rpm = nvr_string + ".src.rpm"
60b7a5f
+        non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
60b7a5f
+        q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % (
60b7a5f
+            src_rpm, non_src_rpm, spec_path)
60b7a5f
+
60b7a5f
+        out = os.popen(q_cmd)
60b7a5f
+        binary_rpms = []
60b7a5f
+        source_rpm = None
60b7a5f
+        while 1:
60b7a5f
+            line = out.readline()
60b7a5f
+            if not line:
60b7a5f
+                break
60b7a5f
+            l = string.split(string.strip(line))
60b7a5f
+            assert(len(l) == 2)
60b7a5f
+            binary_rpms.append(l[1])
60b7a5f
+            # The source rpm is named after the first entry in the spec file
60b7a5f
+            if source_rpm is None:
60b7a5f
+                source_rpm = l[0]
60b7a5f
+
60b7a5f
+        status = out.close()
60b7a5f
+        if status:
60b7a5f
+            raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))
60b7a5f
+
60b7a5f
         self.spawn(rpm_cmd)
60b7a5f
 
60b7a5f
-        # XXX this is a nasty hack -- we really should have a proper way to
60b7a5f
-        # find out the names of the RPM files created; also, this assumes
60b7a5f
-        # that RPM creates exactly one source and one binary RPM.
60b7a5f
         if not self.dry_run:
60b7a5f
             if not self.binary_only:
60b7a5f
-                srpms = glob.glob(os.path.join(rpm_dir['SRPMS'], "*.rpm"))
60b7a5f
-                assert len(srpms) == 1, \
60b7a5f
-                       "unexpected number of SRPM files found: %s" % srpms
60b7a5f
-                dist_file = ('bdist_rpm', 'any',
60b7a5f
-                             self._dist_path(srpms[0]))
60b7a5f
-                self.distribution.dist_files.append(dist_file)
60b7a5f
-                self.move_file(srpms[0], self.dist_dir)
60b7a5f
+                srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
60b7a5f
+                assert(os.path.exists(srpm))
60b7a5f
+                self.move_file(srpm, self.dist_dir)
60b7a5f
 
60b7a5f
             if not self.source_only:
60b7a5f
-                rpms = glob.glob(os.path.join(rpm_dir['RPMS'], "*/*.rpm"))
60b7a5f
-                debuginfo = glob.glob(os.path.join(rpm_dir['RPMS'],
60b7a5f
-                                                   "*/*debuginfo*.rpm"))
60b7a5f
-                if debuginfo:
60b7a5f
-                    rpms.remove(debuginfo[0])
60b7a5f
-                assert len(rpms) == 1, \
60b7a5f
-                       "unexpected number of RPM files found: %s" % rpms
60b7a5f
-                dist_file = ('bdist_rpm', get_python_version(),
60b7a5f
-                             self._dist_path(rpms[0]))
60b7a5f
-                self.distribution.dist_files.append(dist_file)
60b7a5f
-                self.move_file(rpms[0], self.dist_dir)
60b7a5f
-                if debuginfo:
60b7a5f
-                    dist_file = ('bdist_rpm', get_python_version(),
60b7a5f
-                                 self._dist_path(debuginfo[0]))
60b7a5f
-                    self.move_file(debuginfo[0], self.dist_dir)
60b7a5f
+                for rpm in binary_rpms:
60b7a5f
+                    rpm = os.path.join(rpm_dir['RPMS'], rpm)
60b7a5f
+                    if os.path.exists(rpm):
60b7a5f
+                        self.move_file(rpm, self.dist_dir)
60b7a5f
     # run()
60b7a5f
 
60b7a5f
     def _dist_path(self, path):