Commit 01a4694d authored by Greg Ward's avatar Greg Ward

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
parent 69413da7
...@@ -10,7 +10,7 @@ __revision__ = "$Id$" ...@@ -10,7 +10,7 @@ __revision__ = "$Id$"
import os, string import os, string
from types import * from types import *
from distutils.core import Command from distutils.core import Command
from distutils.util import mkpath, write_file, copy_file from distutils.util import get_platform, write_file
from distutils.errors import * from distutils.errors import *
class bdist_rpm (Command): class bdist_rpm (Command):
...@@ -18,6 +18,8 @@ class bdist_rpm (Command): ...@@ -18,6 +18,8 @@ class bdist_rpm (Command):
description = "create an RPM distribution" description = "create an RPM distribution"
user_options = [ user_options = [
('bdist-base', None,
"base directory for creating built distributions"),
('spec-only', None, ('spec-only', None,
"only regenerate spec file"), "only regenerate spec file"),
('source-only', None, ('source-only', None,
...@@ -41,6 +43,7 @@ class bdist_rpm (Command): ...@@ -41,6 +43,7 @@ class bdist_rpm (Command):
def initialize_options (self): def initialize_options (self):
self.bdist_base = None
self.spec_only = None self.spec_only = None
self.binary_only = None self.binary_only = None
self.source_only = None self.source_only = None
...@@ -52,13 +55,14 @@ class bdist_rpm (Command): ...@@ -52,13 +55,14 @@ class bdist_rpm (Command):
def finalize_options (self): def finalize_options (self):
self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
if os.name != 'posix': if os.name != 'posix':
raise DistutilsPlatformError, \ raise DistutilsPlatformError, \
("don't know how to create RPM " ("don't know how to create RPM "
"distributions on platform %s" % os.name) "distributions on platform %s" % os.name)
if self.binary_only and self.source_only: if self.binary_only and self.source_only:
raise DistutilsOptionsError, \ raise DistutilsOptionsError, \
"Cannot supply both '--source-only' and '--binary-only'" "cannot supply both '--source-only' and '--binary-only'"
# don't pass CFLAGS to pure python distributions # don't pass CFLAGS to pure python distributions
if not self.distribution.has_ext_modules(): if not self.distribution.has_ext_modules():
self.use_rpm_opt_flags = 0 self.use_rpm_opt_flags = 0
...@@ -69,50 +73,49 @@ class bdist_rpm (Command): ...@@ -69,50 +73,49 @@ class bdist_rpm (Command):
def run (self): def run (self):
self._get_package_data() # get packaging info self._get_package_data() # get packaging info
# make directories # make directories
if self.spec_only: if self.spec_only:
self.mkpath('redhat') spec_dir = "dist"
self.mkpath(spec_dir) # XXX should be configurable
else: else:
rpm_base = os.path.join(self.bdist_base, "rpm")
rpm_dir = {}
for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'): for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
self.mkpath(os.path.join('build/rpm', d)) rpm_dir[d] = os.path.join(rpm_base, d)
self.mkpath(rpm_dir[d])
# spec file goes into .redhat directory if '--spec-only specified', spec_dir = rpm_dir['SPECS']
# into build/rpm/spec otherwise
if self.spec_only: # Spec file goes into 'dist' directory if '--spec-only specified',
spec_path = 'redhat/%s.spec' % self.distribution.get_name() # into build/rpm.<plat> otherwise.
else: spec_path = os.path.join(spec_dir,
spec_path = ('build/rpm/SPECS/%s.spec' % "%s.spec" % self.distribution.get_name())
self.distribution.get_name())
self.execute(write_file, self.execute(write_file,
(spec_path, (spec_path,
self._make_spec_file()), self._make_spec_file()),
'Writing .spec file') "writing '%s'" % spec_path)
if self.spec_only: # stop if requested if self.spec_only: # stop if requested
return return
# make a source distribution and copy to SOURCES directory with # Make a source distribution and copy to SOURCES directory with
# optional icon # optional icon.
sdist = self.get_finalized_command ('sdist') sdist = self.reinitialize_command ('sdist')
if self.use_bzip2: if self.use_bzip2:
sdist.formats = ['bztar'] sdist.formats = ['bztar']
else: else:
sdist.formats = ['gztar'] sdist.formats = ['gztar']
self.run_command('sdist') self.run_command('sdist')
if self.use_bzip2:
source = self.distribution.get_fullname() + '.tar.bz2' source = sdist.get_archive_files()[0]
else: source_dir = rpm_dir['SOURCES']
source = self.distribution.get_fullname() + '.tar.gz' self.copy_file(source, source_dir)
self.execute(copy_file, (source, 'build/rpm/SOURCES'),
'Copying source distribution to SOURCES')
if self.icon: if self.icon:
if os.path.exists(self.icon): if os.path.exists(self.icon):
self.execute(copy_file, (self.icon, 'build/rpm/SOURCES'), self.copy_file(self.icon, source_dir)
'Copying icon to SOURCES')
else: else:
raise DistutilsFileError, \ raise DistutilsFileError, \
"Unable to find icon file '%s'" % self.icon "icon file '%s' does not exist" % self.icon
# build package # build package
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment