Commit a12c1950 authored by Greg Ward's avatar Greg Ward

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").
parent c0fe82ca
...@@ -8,6 +8,7 @@ distributions).""" ...@@ -8,6 +8,7 @@ distributions)."""
__revision__ = "$Id$" __revision__ = "$Id$"
import os, string import os, string
import glob
from types import * from types import *
from distutils.core import Command, DEBUG from distutils.core import Command, DEBUG
from distutils.util import get_platform from distutils.util import get_platform
...@@ -24,6 +25,9 @@ class bdist_rpm (Command): ...@@ -24,6 +25,9 @@ class bdist_rpm (Command):
('rpm-base=', None, ('rpm-base=', None,
"base directory for creating RPMs (defaults to \"rpm\" under " "base directory for creating RPMs (defaults to \"rpm\" under "
"--bdist-base; must be specified for RPM 2)"), "--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, ('spec-only', None,
"only regenerate spec file"), "only regenerate spec file"),
('source-only', None, ('source-only', None,
...@@ -109,6 +113,7 @@ class bdist_rpm (Command): ...@@ -109,6 +113,7 @@ class bdist_rpm (Command):
def initialize_options (self): def initialize_options (self):
self.bdist_base = None self.bdist_base = None
self.rpm_base = None self.rpm_base = None
self.dist_dir = 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
...@@ -166,6 +171,7 @@ class bdist_rpm (Command): ...@@ -166,6 +171,7 @@ class bdist_rpm (Command):
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
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
self.finalize_package_data() self.finalize_package_data()
# finalize_options() # finalize_options()
...@@ -226,8 +232,8 @@ class bdist_rpm (Command): ...@@ -226,8 +232,8 @@ class bdist_rpm (Command):
# make directories # make directories
if self.spec_only: if self.spec_only:
spec_dir = "dist" spec_dir = self.dist_dir
self.mkpath(spec_dir) # XXX should be configurable self.mkpath(spec_dir)
else: else:
rpm_dir = {} rpm_dir = {}
for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'): for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
...@@ -235,8 +241,8 @@ class bdist_rpm (Command): ...@@ -235,8 +241,8 @@ class bdist_rpm (Command):
self.mkpath(rpm_dir[d]) self.mkpath(rpm_dir[d])
spec_dir = rpm_dir['SPECS'] spec_dir = rpm_dir['SPECS']
# Spec file goes into 'dist' directory if '--spec-only specified', # Spec file goes into 'dist_dir' if '--spec-only specified',
# into build/rpm.<plat> otherwise. # build/rpm.<plat> otherwise.
spec_path = os.path.join(spec_dir, spec_path = os.path.join(spec_dir,
"%s.spec" % self.distribution.get_name()) "%s.spec" % self.distribution.get_name())
self.execute(write_file, self.execute(write_file,
...@@ -285,6 +291,19 @@ class bdist_rpm (Command): ...@@ -285,6 +291,19 @@ class bdist_rpm (Command):
rpm_args.append(spec_path) rpm_args.append(spec_path)
self.spawn(rpm_args) 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() # run()
......
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