[Distutils] Patch for bdist_rpm
Harry Henry Gebel
hgebel@inet.net
Wed, 26 Apr 2000 16:30:51 -0400
--AhhlLboLdkugWU4S
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Okay, three attachments to this message
1) patch against CVS to add bdist_rpm
2) bdist_rpm.py
3) a sample package_data file for Distutils that can be used to build a
Distutils RPM (it will build an RPM without the file)
I have to leave for a meeting, but when I get back I will post
instructions. The patch uses --package-prefix and --record-install, but if
you don't want to use them just change bdist_rpm.py lines 191-192 to the
command you want to use to install.
No options at this time, but I have several I am adding tonight. There are
several caveats to the command as in stands now, they will no longer apply
after I add the options.
--
Harry Henry Gebel, Senior Developer, Landon House SBS
West Dover Hundred, Delaware
PyNcurses ncurses binding for Python: http://pyncurses.sourceforge.net
--AhhlLboLdkugWU4S
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="bdist_rpm.patch"
? build
? MANIFEST
? rpm.patch
? dry_run.patch
? redhat
? package_data
? INSTALLED_FILES
? 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/26 20:26:56
@@ -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/26 20:26:58
@@ -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/26 20:26:58
@@ -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.22
diff -u -r1.22 install.py
--- install.py 2000/04/26 02:38:01 1.22
+++ install.py 2000/04/26 20:27:01
@@ -12,6 +12,7 @@
from distutils import sysconfig
from distutils.util import write_file, native_path, subst_vars
from distutils.errors import DistutilsOptionError
+from glob import glob
INSTALL_SCHEMES = {
'unix_prefix': {
@@ -20,6 +21,12 @@
'scripts': '$base/bin',
'data' : '$base/share',
},
+ 'unix_package_prefix': {
+ 'purelib': '$root/$base/lib/python$py_version_short/site-packages',
+ 'platlib': '$root/$platbase/lib/python$py_version_short/site-packages',
+ 'scripts': '$root/$base/bin',
+ 'data' : '$root/$base/share',
+ },
'unix_home': {
'purelib': '$base/lib/python',
'platlib': '$base/lib/python',
@@ -54,6 +61,11 @@
('home=', None,
"(Unix only) home directory to install under"),
+ # treats package prefix like root directory
+ ('package-prefix=', None,
+ "(For use by packaging systems) prefix is treated like " \
+ "root directory"),
+
# Or, just set the base director(y|ies)
('install-base=', None,
"base installation directory (instead of --prefix or --home)"),
@@ -80,6 +92,9 @@
#('install-man=', None, "directory for Unix man pages"),
#('install-html=', None, "directory for HTML documentation"),
#('install-info=', None, "directory for GNU info files"),
+
+ ('record-install', None,
+ "make a record of installation")
]
@@ -114,6 +129,7 @@
self.install_lib = None # set to either purelib or platlib
self.install_scripts = None
self.install_data = None
+ self.package_prefix = None # will be prepended to any other dirs
# These two are for putting non-packagized distributions into their
# own directory and creating a .pth file if it makes sense.
@@ -138,6 +154,7 @@
#self.install_html = None
#self.install_info = None
+ self.record_install = None
def finalize_options (self):
@@ -167,6 +184,9 @@
raise DistutilsOptionError, \
("must supply either home or prefix/exec-prefix -- " +
"not both")
+ if self.home and self.package_prefix:
+ raise DistutilsOptionError, \
+ ("cannot supply both home and package prefix")
else:
if self.exec_prefix:
self.warn ("exec-prefix option ignored on this platform")
@@ -174,6 +194,9 @@
if self.home:
self.warn ("home option ignored on this platform")
self.home = None
+ if self.package_prefix: # for now
+ self.warn ("package-prefix option ignored on this platform")
+ self.package_prefix = None
# Now the interesting logic -- so interesting that we farm it out
# to other methods. The goal of these methods is to set the final
@@ -213,6 +236,7 @@
# everything else.
self.config_vars['base'] = self.install_base
self.config_vars['platbase'] = self.install_platbase
+ self.config_vars['root'] = self.package_prefix
print "config vars:"
pprint (self.config_vars)
@@ -296,7 +320,10 @@
self.install_base = self.prefix
self.install_platbase = self.exec_prefix
- self.select_scheme ("unix_prefix")
+ if self.package_prefix:
+ self.select_scheme("unix_package_prefix")
+ else:
+ self.select_scheme ("unix_prefix")
# finalize_unix ()
@@ -404,6 +431,22 @@
"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_install:
+ 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.package_prefix: # strip any package prefix
+ prefix_len = len(self.package_prefix) + 1
+ for counter in xrange (len (outputs)):
+ outputs[counter] = outputs[counter][prefix_len:]
+ self.execute(write_file,
+ ("INSTALLED_FILES", outputs),
+ "Writing list of installed files")
# run ()
--AhhlLboLdkugWU4S
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'''
--AhhlLboLdkugWU4S
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
from distutils.core import Command
from distutils.util import mkpath, write_file
from distutils.errors import *
from string import join
class bdist_rpm (Command):
description = "create an RPM distribution"
user_options = []
def initialize_options (self):
pass
# 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
# 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')
# make a .gz distribution
sdist = self.find_peer ('sdist')
sdist.set_option ('formats', ['gztar'])
self.run_peer('sdist')
# build package
self.announce('Building RPMs')
self.spawn(['rpm', '-ta', '--clean',
self.distribution.get_fullname() + '.tar.gz'])
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() '''
# 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 'decription' 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 --package-prefix $RPM_BUILD_ROOT '
'--record-install',
'',
'%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()
--AhhlLboLdkugWU4S--