Patch from Harry Henry Gebel:

Fills in question marks in help

Reads scripts in from files rather than strings

Adds RPM 2 compatibility mode (untested). Use of this mode requires that
--bdist-base be specified because bdist_rpm has no way of detecting where
RPM wants to find spec files and source files. An unmodified RedHat 5.0
system would require '--bdist-base=/usr/src/RedHat'. (You would also have
to be root.) If the rpmrc file has been modified to allow RPMs to be built
by normal users then --build-base would need to be changed accordingly.

Formats the changelog.

GPW: tweaked formatting, added some editorial comments.
This commit is contained in:
Greg Ward 2000-06-04 15:00:34 +00:00
parent 31413a7ba2
commit a68c93ac89
1 changed files with 103 additions and 59 deletions

View File

@ -42,7 +42,7 @@ class bdist_rpm (Command):
('release', None, ('release', None,
"RPM release number"), "RPM release number"),
('serial', None, ('serial', None,
"???"), "RPM serial number"),
('vendor', None, ('vendor', None,
"RPM \"vendor\" (eg. \"Joe Blow <joe@example.com>\") " "RPM \"vendor\" (eg. \"Joe Blow <joe@example.com>\") "
"[default: maintainer or author from setup script]"), "[default: maintainer or author from setup script]"),
@ -52,18 +52,17 @@ class bdist_rpm (Command):
('doc-files', None, ('doc-files', None,
"list of documentation files (space or comma-separated)"), "list of documentation files (space or comma-separated)"),
('changelog', None, ('changelog', None,
"RPM changelog"), "path to RPM changelog"),
('icon', None, ('icon', None,
"name of icon file"), "name of icon file"),
('prep-script', None,
('prep-cmd', None, "pre-build script (Bourne shell code)"),
"?? pre-build command(s) ??"), ('build-script', None,
('build-cmd', None, "build script (Bourne shell code)"),
"?? build command(s) ??"), ('install-script', None,
('install-cmd', None, "installation script (Bourne shell code)"),
"?? installation command(s) ??"), ('clean-script', None,
('clean-cmd', None, "clean script (Bourne shell code)"),
"?? clean command(s) ??"),
('pre-install', None, ('pre-install', None,
"pre-install script (Bourne shell code)"), "pre-install script (Bourne shell code)"),
('post-install', None, ('post-install', None,
@ -72,17 +71,16 @@ class bdist_rpm (Command):
"pre-uninstall script (Bourne shell code)"), "pre-uninstall script (Bourne shell code)"),
('post-uninstall', None, ('post-uninstall', None,
"post-uninstall script (Bourne shell code)"), "post-uninstall script (Bourne shell code)"),
('provides', None, ('provides', None,
"???"), "capabilities provided by this package"),
('requires', None, ('requires', None,
"???"), "capabilities required by this package"),
('conflicts', None, ('conflicts', None,
"???"), "capabilities which conflict with this package"),
('build-requires', None, ('build-requires', None,
"???"), "capabilities required to build this package"),
('obsoletes', None, ('obsoletes', None,
"???"), "capabilities made obsolete by this package"),
# Actions to take when building RPM # Actions to take when building RPM
('clean', None, ('clean', None,
@ -93,10 +91,15 @@ class bdist_rpm (Command):
"compile with RPM_OPT_FLAGS when building from source RPM"), "compile with RPM_OPT_FLAGS when building from source RPM"),
('no-rpm-opt-flags', None, ('no-rpm-opt-flags', None,
"do not pass any RPM CFLAGS to compiler"), "do not pass any RPM CFLAGS to compiler"),
('rpm3-mode', None,
"RPM 3 compatibility mode (default)"),
('rpm2-mode', None,
"RPM 2 compatibility mode"),
] ]
negative_opt = {'no-clean': 'clean', negative_opt = {'no-clean': 'clean',
'no-rpm-opt-flags': 'use-rpm-opt-flags'} 'no-rpm-opt-flags': 'use-rpm-opt-flags',
'rpm2-mode': 'rpm3-mode'}
def initialize_options (self): def initialize_options (self):
@ -116,10 +119,10 @@ def initialize_options (self):
self.changelog = None self.changelog = None
self.icon = None self.icon = None
self.prep_cmd = None self.prep_script = None
self.build_cmd = None self.build_script = None
self.install_cmd = None self.install_script = None
self.clean_cmd = None self.clean_script = None
self.pre_install = None self.pre_install = None
self.post_install = None self.post_install = None
self.pre_uninstall = None self.pre_uninstall = None
@ -133,6 +136,7 @@ def initialize_options (self):
self.clean = 1 self.clean = 1
self.use_rpm_opt_flags = 1 self.use_rpm_opt_flags = 1
self.rpm3_mode = 1
# initialize_options() # initialize_options()
@ -160,31 +164,28 @@ def finalize_package_data (self):
self.ensure_string('vendor', self.ensure_string('vendor',
"%s <%s>" % (self.distribution.get_contact(), "%s <%s>" % (self.distribution.get_contact(),
self.distribution.get_contact_email())) self.distribution.get_contact_email()))
self.ensure_string('packager', self.vendor) # or nothing? self.ensure_string('packager')
self.ensure_string_list('doc_files') self.ensure_string_list('doc_files')
if type(self.doc_files) is ListType: if type(self.doc_files) is ListType:
for readme in ('README', 'README.txt'): for readme in ('README', 'README.txt'):
if os.path.exists(readme) and readme not in self.doc_files: if os.path.exists(readme) and readme not in self.doc_files:
self.doc.append(readme) self.doc.append(readme)
self.ensure_string('release', "1") # should it be an int? self.ensure_string('release', "1")
self.ensure_string('serial') # should it be an int? self.ensure_string('serial') # should it be an int?
self.ensure_string('icon')
self.ensure_string('distribution_name') self.ensure_string('distribution_name')
self.ensure_string('prep_cmd', "%setup") # string or filename? self.ensure_string('changelog')
# Format changelog correctly
self.changelog = self._format_changelog(self.changelog)
if self.use_rpm_opt_flags: self.ensure_filename('icon')
def_build = 'env CFLAGS="$RPM_OPT_FLAGS" python setup.py build'
else: self.ensure_filename('prep_script')
def_build = 'python setup.py build' self.ensure_filename('build_script')
self.ensure_string('build_cmd', def_build) self.ensure_filename('install_script')
self.ensure_string('install_cmd', self.ensure_filename('clean_script')
"python setup.py install --root=$RPM_BUILD_ROOT "
"--record=INSTALLED_FILES")
self.ensure_string('clean_cmd',
"rm -rf $RPM_BUILD_ROOT")
self.ensure_filename('pre_install') self.ensure_filename('pre_install')
self.ensure_filename('post_install') self.ensure_filename('post_install')
self.ensure_filename('pre_uninstall') self.ensure_filename('pre_uninstall')
@ -217,7 +218,11 @@ def run (self):
spec_dir = "dist" spec_dir = "dist"
self.mkpath(spec_dir) # XXX should be configurable self.mkpath(spec_dir) # XXX should be configurable
else: else:
rpm_base = os.path.join(self.bdist_base, "rpm") if self.rpm3_mode:
rpm_base = os.path.join(self.bdist_base, "rpm")
else:
# complete path must be specified in RPM 2 mode
rpm_base = self.bdist_base
rpm_dir = {} rpm_dir = {}
for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'): for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
rpm_dir[d] = os.path.join(rpm_base, d) rpm_dir[d] = os.path.join(rpm_base, d)
@ -266,8 +271,9 @@ def run (self):
rpm_args.append('-bb') rpm_args.append('-bb')
else: else:
rpm_args.append('-ba') rpm_args.append('-ba')
rpm_args.extend(['--define', if self.rpm3_mode:
'_topdir %s/%s' % (os.getcwd(), rpm_base),]) rpm_args.extend(['--define',
'_topdir %s/%s' % (os.getcwd(), rpm_base),])
if self.clean: if self.clean:
rpm_args.append('--clean') rpm_args.append('--clean')
rpm_args.append(spec_path) rpm_args.append(spec_path)
@ -363,27 +369,45 @@ def _make_spec_file(self):
# ]) # ])
# rpm scripts # rpm scripts
for (rpm_opt, attr) in (('prep', 'prep_cmd'), # figure out default build script
('build', 'build_cmd'), if self.use_rpm_opt_flags:
('install', 'install_cmd'), def_build = 'env CFLAGS="$RPM_OPT_FLAGS" python setup.py build'
('clean', 'clean_cmd'), else:
('pre', 'pre_install'), def_build = 'python setup.py build'
('post', 'post_install'), # insert contents of files
('preun', 'pre_uninstall'),
('postun', 'post_uninstall')): # XXX this is kind of misleading: user-supplied options are files
# XXX oops, this doesn't distinguish between "raw code" # that we open and interpolate into the spec file, but the defaults
# options and "script filename" options -- well, we probably # are just text that we drop in as-is. Hmmm.
# should settle on one or the other, and not make the
# distinction! script_options = [
('prep', 'prep_script', "%setup"),
('build', 'build_script', def_build),
('install', 'install_script',
"python setup.py install "
"--root=$RPM_BUILD_ROOT "
"--record=INSTALLED_FILES"),
('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"),
('pre', 'pre_install', None),
('post', 'post_install', None),
('preun', 'pre_uninstall', None),
('postun', 'post_uninstall', None))
]
for (rpm_opt, attr, default) in script_options:
# Insert contents of file refered to, if no file is refered to
# use 'default' as contents of script
val = getattr(self, attr) val = getattr(self, attr)
if val: if val or default:
spec_file.extend([ spec_file.extend([
'', '',
'%' + rpm_opt, '%' + rpm_opt,])
val if val:
]) spec_file.extend(string.split(open(val, 'r').read(), '\n'))
else:
spec_file.append(default)
# files section # files section
spec_file.extend([ spec_file.extend([
'', '',
@ -397,12 +421,32 @@ def _make_spec_file(self):
if self.changelog: if self.changelog:
spec_file.extend([ spec_file.extend([
'', '',
'%changelog', '%changelog',])
self.changelog spec_file.extend(self.changelog)
])
return spec_file return spec_file
# _make_spec_file () # _make_spec_file ()
def _format_changelog(self, changelog):
"""Format the changelog correctly and convert it to a list of strings
"""
new_changelog = []
for line in string.split(string.strip(changelog), '\n'):
line = string.strip(line)
if line[0] == '*':
new_changelog.extend(['', line])
elif line[0] == '-':
new_changelog.append(line)
else:
new_changelog.append(' ' + line)
# strip trailing newline inserted by first changelog entry
if not new_changelog[0]:
del new_changelog[0]
return new_changelog
# _format_changelog()
# class bdist_rpm # class bdist_rpm