[Distutils] Update bdist_rpm patch
Harry Henry Gebel
hgebel@inet.net
Thu, 27 Apr 2000 05:50:48 -0400
--OBd5C1Lgu00Gd/Tn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Okay, here is a new version of the bdist_rpm patch, it adds the following
options:
--spec-only - This option just generates a spec file and then stops
--tar-only - This option just generates a tarball and stops. The command
`rpm -ta program_name.tar.gz` will then build an RPM
--no-remove - bdist_rpm now by default will remove MANIFEST, redhat/, and
program_name.tar.gz when run as root. This option will
disable this behavior
--arch - This option will build the RPM for the specified
architecture.
One important consideration for --arch : Unless ./setup.py can be made to
recognize the rpm's CFLAGS it will generate the same object code no matter
what architecture you specify. In this case --arch will only effect what
rpm THINKS the package is. I looked through the ccompiler and
unixccompiler modules and didn't find any way to pass any CFLAGS in either
through the command line or through an environment variable, am I missing
it or has this feature not been added yet?
--
Harry Henry Gebel, Senior Developer, Landon House SBS
West Dover Hundred, Delaware
PyNcurses ncurses binding for Python: http://pyncurses.sourceforge.net
--OBd5C1Lgu00Gd/Tn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="bdist_rpm.patch"
? build
? redhat
? rpm.patch
? dry_run.patch
? MANIFEST
? package_data
? install_options.patch
? long_description.patch
? exeception_error.patch
? bdist_rpm.patch
? Distutils-0.8.2.tar.gz
? distutils/command/bdist_rpm.py
Index: MANIFEST.in
===================================================================
RCS file: /projects/cvsroot/distutils/MANIFEST.in,v
retrieving revision 1.4
diff -u -r1.4 MANIFEST.in
--- MANIFEST.in 2000/04/21 04:38:11 1.4
+++ MANIFEST.in 2000/04/27 09:29:32
@@ -9,7 +9,9 @@
#
include *.txt
+include package_data
include MANIFEST.in
+include redhat/*.spec
recursive-include examples *.txt *.py
prune examples/sample?/build
recursive-include doc *.sty *.tex
Index: distutils/command/__init__.py
===================================================================
RCS file: /projects/cvsroot/distutils/distutils/command/__init__.py,v
retrieving revision 1.8
diff -u -r1.8 __init__.py
--- __init__.py 2000/03/31 03:14:51 1.8
+++ __init__.py 2000/04/27 09:29:35
@@ -15,4 +15,5 @@
'sdist',
'bdist',
'bdist_dumb',
+ 'bdist_rpm',
]
Index: distutils/command/bdist.py
===================================================================
RCS file: /projects/cvsroot/distutils/distutils/command/bdist.py,v
retrieving revision 1.5
diff -u -r1.5 bdist.py
--- bdist.py 2000/04/25 01:38:19 1.5
+++ bdist.py 2000/04/27 09:29:35
@@ -31,8 +31,12 @@
'bztar': 'bdist_dumb',
'ztar': 'bdist_dumb',
'tar': 'bdist_dumb',
- 'zip': 'bdist_dumb', }
+ 'zip': 'bdist_dumb',
+ 'rpm': 'bdist_rpm',
+ }
+ # The following commands do not take a format option from bdist
+ no_format_option = ( 'bdist_rpm', )
def initialize_options (self):
self.format = None
@@ -63,8 +67,9 @@
raise DistutilsOptionError, \
"invalid archive format '%s'" % self.format
- sub_cmd = self.find_peer (cmd_name)
- sub_cmd.set_option ('format', self.format)
+ if cmd_name not in self.no_format_option:
+ sub_cmd = self.find_peer (cmd_name)
+ sub_cmd.set_option ('format', self.format)
self.run_peer (cmd_name)
# run()
Index: distutils/command/install.py
===================================================================
RCS file: /projects/cvsroot/distutils/distutils/command/install.py,v
retrieving revision 1.23
diff -u -r1.23 install.py
--- install.py 2000/04/27 01:56:38 1.23
+++ install.py 2000/04/27 09:29:38
@@ -12,6 +12,7 @@
from distutils import sysconfig
from distutils.util import write_file, native_path, subst_vars, change_root
from distutils.errors import DistutilsOptionError
+from glob import glob
INSTALL_SCHEMES = {
'unix_prefix': {
@@ -82,9 +83,11 @@
#('install-man=', None, "directory for Unix man pages"),
#('install-html=', None, "directory for HTML documentation"),
#('install-info=', None, "directory for GNU info files"),
- ]
+ ('record', None,
+ "make a record of installation")]
+
# 'sub_commands': a list of commands this command might have to run
# to get its work done. Each command is represented as a tuple
# (func, command) where 'func' is a function to call that returns
@@ -141,6 +144,7 @@
#self.install_html = None
#self.install_info = None
+ self.record_install = None
def finalize_options (self):
@@ -267,7 +271,8 @@
from distutils.fancy_getopt import longopt_xlate
print msg + ":"
for opt in self.user_options:
- opt_name = string.translate (opt[0][0:-1], longopt_xlate)
+ if opt[0][-1] == '=':
+ opt_name = string.translate (opt[0][0:-1], longopt_xlate)
val = getattr (self, opt_name)
print " %s: %s" % (opt_name, val)
@@ -424,6 +429,24 @@
"Python's module search path (sys.path) -- " +
"you'll have to change the search path yourself") %
self.install_lib)
+
+
+ # write list of installed files, if requested.
+ if self.record:
+ outputs = self.get_outputs()
+ for counter in xrange (len (outputs)): # include ".pyc" and ".pyo"
+ if outputs[counter][-3:] == ".py":
+ byte_code = glob(outputs[counter] + '[co]')
+ outputs.extend(byte_code)
+ outputs.sort() # just makes it look nicer
+ if self.root: # strip any package prefix
+ root_len = len(self.root)
+ for counter in xrange (len (outputs)):
+ outputs[counter] = outputs[counter][root_len:]
+ self.execute(write_file,
+ ("INSTALLED_FILES", outputs),
+ "Writing list of installed files")
+
# run ()
--OBd5C1Lgu00Gd/Tn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=package_data
release = '1'
group = 'Development/Libraries'
vendor = 'Distutils-SIG'
packager = 'Harry Henry Gebel <hgebel@inet.net>'
doc = ['CHANGES.txt',
'README.txt',
'USAGE.txt',
'doc/',
'examples/',
]
changelog = '''\
* Wed Apr 26 2000 Harry Henry Gebel 0.8.2-1
- First test of bdist_rpm'''
--OBd5C1Lgu00Gd/Tn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="bdist_rpm.py"
"""distutils.command.bdist_rpm
Implements the Distutils 'bdist_rpm' command (create RPM source and binary
distributions."""
# created 2000/04/25, Greg Ward
__revision__ = "$Id: bdist_dumb.py,v 1.3 2000/04/22 02:51:25 gward Exp $"
import os.path
import os
from distutils.core import Command
from distutils.util import mkpath, write_file, remove_tree
from distutils.errors import *
from string import join
class bdist_rpm (Command):
description = "create an RPM distribution"
user_options = [
('spec-only', None,
"Only regenerate spec file"),
('tar-only', None,
"Only generate spec file and tarball"),
('no-remove', None,
"Do not remove root owned files"),
('arch=', None,
"Build for a specific architecture"),
]
def initialize_options (self):
self.spec_only = None
self.tar_only = None
self.no_remove = None
self.arch = None
# initialize_options()
def finalize_options (self):
if os.name != 'posix':
raise DistutilsPlatformError, \
("don't know how to create RPM "
"distributions on platform %s") % os.name
if self.spec_only and self.tar_only:
raise DistutilsOptionsError, \
'Cannot specify both spec-only and tar-only'
if os.getuid(): # if not root
if self.no_remove:
self.warn('no-remave has no effect when not root')
self.remove = None
else: # if root
if self.no_remove:
self.remove = None
else:
self.remove = 1
# finalize_options()
def run (self):
self._getPackageData() # get packaging info
# place spec file in ./redhat directory
self.execute(mkpath, ('./redhat',), "Created ./redhat directory")
spec_path = './redhat/%s.spec' % self.name
self.execute(write_file,
(spec_path,
self._makeSpecFile()),
'Writing .spec file')
if self.spec_only: # stop if requested
return
# make a .gz distribution
sdist = self.find_peer ('sdist')
sdist.set_option ('formats', ['gztar'])
self.run_peer('sdist')
if self.tar_only: # stop if requested
return
# build package
self.announce('Building RPMs')
rpm_args = ['rpm', '-ta', '--clean']
if self.arch and self.distribution.has_ext_modules():
rpm_args.append['--target=' + arch]
rpm_args.append(self.distribution.get_fullname() + '.tar.gz')
self.spawn(rpm_args)
if self.remove: # remove generated files
self.execute(self._remove_root, (), 'Removing generated files')
def _remove_root(self):
''' Remove files generated to support rpm '''
os.unlink('MANIFEST')
os.unlink(self.distribution.get_fullname() + '.tar.gz')
remove_tree('redhat')
def _getPackageData(self):
''' Get data needed to generate spec file, first from the
DistributionMetadata class, then from the package_data file, which is
Python code read with execfile() '''
package_type = 'rpm'
# read in package data, if any
if os.path.exists('package_data'):
try:
exec(open('package_data'))
except:
raise DistutilsOptionError, 'Error in package data file'
# set instance variables, supplying default value if not provided in
# package data file
vars = locals().keys()
if 'name' in vars:
self.name = name
else:
self.name = self.distribution.get_name()
if 'version' in vars:
self.version = version
else:
self.version = self.distribution.get_version()
if 'summary' in vars:
self.summary = summary
else:
self.summary = self.distribution.get_description()
if 'description' in vars:
self.description = description
else:
self.description = self.distribution.get_long_description()
if 'summaries' in vars:
self.summaries = summaries
else:
self.summaries = {}
if 'descriptions' in vars:
self.descriptions = descriptions
else:
self.descriptions = {}
if 'copyright' in vars:
self.copyright = copyright
else:
self.copyright = self.distribution.get_licence()
if 'release' in vars:
self.release = release
else:
self.release = '1'
if 'group' in vars:
self.group = group
else:
self.group = 'Applications'
if 'vendor' in vars:
self.vendor = vendor
else:
self.vendor = None
if 'packager' in vars:
self.packager = packager
else:
self.packager = None
if 'url' in vars:
self.url = url
else:
self.url = self.distribution.get_url()
if 'doc' in vars:
self.doc = join(doc, ' ')
else:
self.doc = None
if 'changelog' in vars:
self.changelog = changelog
else:
self.changelog = None
def _makeSpecFile(self):
''' Generate an RPM spec file '''
spec_file = [
'%define name ' + self.name,
'%define version ' + self.version,
'%define release ' + self.release,
'',
'Summary: ' + self.summary, ]
# put locale summaries into spec file
for locale in self.summaries.keys():
spec_file.append('Summary(%s): %s' % (locale,
self.summaries[locale]))
spec_file.extend([
'Name: %{name}',
'Version: %{version}',
'Release: %{release}',
'Source0: %{name}-%{version}.tar.gz',
'Copyright: ' + self.copyright,
'Group: ' + self.group,
'BuildRoot: %{_tmppath}/%{name}-buildroot',
'Prefix: %{_prefix}', ])
if not self.distribution.has_ext_modules():
spec_file.append('BuildArchitectures: noarch')
if self.vendor:
spec_file.append('Vendor: ' + self.vendor)
if self.packager:
spec_file.append('Packager: ' + self.packager)
if self.url:
spec_file.append('Url: ' + self.url)
spec_file.extend([
'',
'%description',
self.description])
# put locale descriptions into spec file
for locale in self.descriptions.keys():
spec_file.extend([
'',
'%description -l ' + locale,
self.descriptions[locale],
])
spec_file.extend([
'',
'%prep',
'%setup',
'',
'%build',
'python setup.py build',
'',
'%install',
'python setup.py install --root=$RPM_BUILD_ROOT '
'--record',
'',
'%clean',
'rm -rf $RPM_BUILD_ROOT',
'rm -f INSTALLED_FILES',
'',
'%files -f INSTALLED_FILES',
'%defattr(-,root,root)',
])
if self.doc:
spec_file.append('%doc ' + self.doc)
if self.changelog:
spec_file.extend([
'',
'%changelog',
self.changelog
])
return spec_file
# run()
--OBd5C1Lgu00Gd/Tn--