[Python-checkins] CVS: distutils/distutils/command bdist_rpm.py,1.15,1.16

Greg Ward python-dev@python.org
Tue, 15 Aug 2000 06:03:19 -0700


Update of /cvsroot/python/distutils/distutils/command
In directory slayer.i.sourceforge.net:/tmp/cvs-serv27293

Modified Files:
	bdist_rpm.py 
Log Message:
Added support for the '--dist-dir' option, including a mildly nasty
hack to find the two created RPM files (source and binary) and
move them to the "dist dir" (default "dist").


Index: bdist_rpm.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/command/bdist_rpm.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** bdist_rpm.py	2000/08/05 01:31:54	1.15
--- bdist_rpm.py	2000/08/15 13:03:16	1.16
***************
*** 9,12 ****
--- 9,13 ----
  
  import os, string
+ import glob
  from types import *
  from distutils.core import Command, DEBUG
***************
*** 25,28 ****
--- 26,32 ----
           "base directory for creating RPMs (defaults to \"rpm\" under "
           "--bdist-base; must be specified for RPM 2)"),
+         ('dist-dir=', 'd',
+          "directory to put final RPM files in "
+          "(and .spec files if --spec-only)"),
          ('spec-only', None,
           "only regenerate spec file"),
***************
*** 110,113 ****
--- 114,118 ----
          self.bdist_base = None
          self.rpm_base = None
+         self.dist_dir = None
          self.spec_only = None
          self.binary_only = None
***************
*** 167,170 ****
--- 172,176 ----
              self.use_rpm_opt_flags = 0
  
+         self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
          self.finalize_package_data()
  
***************
*** 227,232 ****
          # make directories
          if self.spec_only:
!             spec_dir = "dist"
!             self.mkpath(spec_dir)       # XXX should be configurable
          else:
              rpm_dir = {}
--- 233,238 ----
          # make directories
          if self.spec_only:
!             spec_dir = self.dist_dir
!             self.mkpath(spec_dir)
          else:
              rpm_dir = {}
***************
*** 236,241 ****
              spec_dir = rpm_dir['SPECS']
  
!         # Spec file goes into 'dist' directory if '--spec-only specified',
!         # into build/rpm.<plat> otherwise.
          spec_path = os.path.join(spec_dir,
                                   "%s.spec" % self.distribution.get_name())
--- 242,247 ----
              spec_dir = rpm_dir['SPECS']
  
!         # Spec file goes into 'dist_dir' if '--spec-only specified',
!         # build/rpm.<plat> otherwise.
          spec_path = os.path.join(spec_dir,
                                   "%s.spec" % self.distribution.get_name())
***************
*** 285,288 ****
--- 291,307 ----
          rpm_args.append(spec_path)
          self.spawn(rpm_args)
+ 
+         # XXX this is a nasty hack -- we really should have a proper way to
+         # find out the names of the RPM files created; also, this assumes
+         # that RPM creates exactly one source and one binary RPM.
+         if not self.dry_run:
+             srpms = glob.glob(os.path.join(rpm_dir['SRPMS'], "*.rpm"))
+             rpms = glob.glob(os.path.join(rpm_dir['RPMS'], "*/*.rpm"))
+             assert len(srpms) == 1, \
+                    "unexpected number of SRPM files found: %s" % srpms
+             assert len(rpms) == 1, \
+                    "unexpected number of RPM files found: %s" % rpms
+             self.move_file(srpms[0], self.dist_dir)
+             self.move_file(rpms[0], self.dist_dir)
  
      # run()