[Python-checkins] CVS: distutils/distutils/command bdist_rpm.py,1.4,1.5

Greg Ward python-dev@python.org
Wed, 31 May 2000 17:40:27 -0700


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

Modified Files:
	bdist_rpm.py 
Log Message:
More tweaking to make this command act like other Distutils commands:
  * added "--bdist-base" option to parameterize where we build
    the RPM (comes from "bdist" by default: "build/bdist.<plat>")
  * simplified/cleaned up some code in 'run()' in the process of
    removing (most) hard-coded directory names
  * if "--spec-only", drop spec file in "dist" rather than "redhat"
    (directory name still hard-coded, though)
  * use 'reinitialize_command()' to fetch the "sdist" object to
    tweak before running "sdist" command
  * use 'self.copy_file()' method rather than 'copy_file()' function 
  * cosmetic tweaks to comments, error messages


Index: bdist_rpm.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/command/bdist_rpm.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** bdist_rpm.py	2000/05/31 23:56:45	1.4
--- bdist_rpm.py	2000/06/01 00:40:25	1.5
***************
*** 6,15 ****
  # created 2000/04/25, by Harry Henry Gebel
  
! __revision__ = "$Id: bdist_rpm.py,v 1.4 2000/05/31 23:56:45 gward Exp $"
  
  import os, string
  from types import *
  from distutils.core import Command
! from distutils.util import mkpath, write_file, copy_file
  from distutils.errors import *
  
--- 6,15 ----
  # created 2000/04/25, by Harry Henry Gebel
  
! __revision__ = "$Id: bdist_rpm.py,v 1.5 2000/06/01 00:40:25 gward Exp $"
  
  import os, string
  from types import *
  from distutils.core import Command
! from distutils.util import get_platform, write_file
  from distutils.errors import *
  
***************
*** 19,22 ****
--- 19,24 ----
  
      user_options = [
+         ('bdist-base', None,
+          "base directory for creating built distributions"),
          ('spec-only', None,
           "only regenerate spec file"),
***************
*** 42,45 ****
--- 44,48 ----
                      
      def initialize_options (self):
+         self.bdist_base = None
          self.spec_only = None
          self.binary_only = None
***************
*** 53,56 ****
--- 56,60 ----
  
      def finalize_options (self):
+         self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
          if os.name != 'posix':
              raise DistutilsPlatformError, \
***************
*** 59,63 ****
          if self.binary_only and self.source_only:
              raise DistutilsOptionsError, \
!                   "Cannot supply both '--source-only' and '--binary-only'"
          # don't pass CFLAGS to pure python distributions
          if not self.distribution.has_ext_modules():
--- 63,67 ----
          if self.binary_only and self.source_only:
              raise DistutilsOptionsError, \
!                   "cannot supply both '--source-only' and '--binary-only'"
          # don't pass CFLAGS to pure python distributions
          if not self.distribution.has_ext_modules():
***************
*** 70,99 ****
          self._get_package_data() # get packaging info
  
- 
          # make directories
          if self.spec_only:
!             self.mkpath('redhat')
          else:
              for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
!                 self.mkpath(os.path.join('build/rpm', d))
! 
!         # spec file goes into .redhat directory if '--spec-only specified',
!         # into build/rpm/spec otherwise
!         if self.spec_only:
!             spec_path = 'redhat/%s.spec' % self.distribution.get_name()
!         else:
!             spec_path = ('build/rpm/SPECS/%s.spec' %
!                          self.distribution.get_name())
          self.execute(write_file,
                       (spec_path,
                        self._make_spec_file()),
!                      'Writing .spec file')
  
          if self.spec_only: # stop if requested
              return
  
!         # make a source distribution and copy to SOURCES directory with
!         # optional icon
!         sdist = self.get_finalized_command ('sdist')
          if self.use_bzip2:
              sdist.formats = ['bztar']
--- 74,104 ----
          self._get_package_data() # get packaging info
  
          # make directories
          if self.spec_only:
!             spec_dir = "dist"
!             self.mkpath(spec_dir)       # XXX should be configurable
          else:
+             rpm_base = os.path.join(self.bdist_base, "rpm")
+             rpm_dir = {}
              for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
!                 rpm_dir[d] = os.path.join(rpm_base, d)
!                 self.mkpath(rpm_dir[d])
!             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())
          self.execute(write_file,
                       (spec_path,
                        self._make_spec_file()),
!                      "writing '%s'" % spec_path)
  
          if self.spec_only: # stop if requested
              return
  
!         # Make a source distribution and copy to SOURCES directory with
!         # optional icon.
!         sdist = self.reinitialize_command ('sdist')
          if self.use_bzip2:
              sdist.formats = ['bztar']
***************
*** 101,117 ****
              sdist.formats = ['gztar']
          self.run_command('sdist')
!         if self.use_bzip2:
!             source = self.distribution.get_fullname() + '.tar.bz2'
!         else:
!             source = self.distribution.get_fullname() + '.tar.gz'
!         self.execute(copy_file, (source, 'build/rpm/SOURCES'),
!                      'Copying source distribution to SOURCES')
          if self.icon:
              if os.path.exists(self.icon):
!                 self.execute(copy_file, (self.icon, 'build/rpm/SOURCES'),
!                      'Copying icon to SOURCES')
              else:
                  raise DistutilsFileError, \
!                       "Unable to find icon file '%s'" % self.icon
          
  
--- 106,120 ----
              sdist.formats = ['gztar']
          self.run_command('sdist')
! 
!         source = sdist.get_archive_files()[0]
!         source_dir = rpm_dir['SOURCES']
!         self.copy_file(source, source_dir)
! 
          if self.icon:
              if os.path.exists(self.icon):
!                 self.copy_file(self.icon, source_dir)
              else:
                  raise DistutilsFileError, \
!                       "icon file '%s' does not exist" % self.icon