[Distutils] Patch to bdist_rpm

Harry Henry Gebel hgebel@inet.net
Sun, 4 Jun 2000 03:07:00 -0400


--LQksG6bCIzRHxTLp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Here is a patch to bdist_rpm. It does the following:

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.

-- 
Harry Henry Gebel, Senior Developer, Landon House SBS
West Dover Hundred, Delaware

--LQksG6bCIzRHxTLp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="bdist_rpm.patch"

Index: setup.cfg
===================================================================
RCS file: /cvsroot/python/distutils/setup.cfg,v
retrieving revision 1.1
diff -u -r1.1 setup.cfg
--- setup.cfg	2000/06/02 02:07:43	1.1
+++ setup.cfg	2000/06/04 06:54:04
@@ -19,7 +19,7 @@
 formats=gztar,zip
 
 [bdist_rpm]
-release = 3
+release = 1
 packager = Harry Henry Gebel <hgebel@inet.net>
 doc_files = CHANGES.txt
             README.txt
@@ -28,6 +28,10 @@
             examples/
 
 changelog =
+  * Sun Jun 04 2000 Harry Henry Gebel <hgebel@inet.net> 0.9pre-1
+  - Made sure scripts are file names, filled in some help strings, formatted
+    changelog correctly
+
   * Wed May 31 2000 Greg Ward <gward@python.net> 0.8.3pre-1
   - Hacked up bdist_rpm.py, moved meta-data into setup.cfg
 
Index: distutils/command/bdist_rpm.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/command/bdist_rpm.py,v
retrieving revision 1.9
diff -u -r1.9 bdist_rpm.py
--- distutils/command/bdist_rpm.py	2000/06/03 01:03:55	1.9
+++ distutils/command/bdist_rpm.py	2000/06/04 06:54:06
@@ -42,7 +42,7 @@
         ('release', None,
          "RPM release number"),
         ('serial', None,
-         "???"),
+         "RPM serial number"),
         ('vendor', None,
          "RPM \"vendor\" (eg. \"Joe Blow <joe@example.com>\") "
          "[default: maintainer or author from setup script]"),
@@ -52,18 +52,17 @@
         ('doc-files', None,
          "list of documentation files (space or comma-separated)"),
         ('changelog', None,
-         "RPM changelog"),
+         "path to RPM changelog"),
         ('icon', None,
          "name of icon file"),
-
-        ('prep-cmd', None,
-         "?? pre-build command(s) ??"),
-        ('build-cmd', None,
-         "?? build command(s) ??"),
-        ('install-cmd', None,
-         "?? installation command(s) ??"),
-        ('clean-cmd', None,
-         "?? clean command(s) ??"),
+        ('prep-script', None,
+         "pre-build script  (Bourne shell code)"),
+        ('build-script', None,
+         "build script (Bourne shell code)"),
+        ('install-script', None,
+         "installation script (Bourne shell code)"),
+        ('clean-script', None,
+         "clean script (Bourne shell code)"),
         ('pre-install', None,
          "pre-install script (Bourne shell code)"),
         ('post-install', None,
@@ -72,17 +71,16 @@
          "pre-uninstall script (Bourne shell code)"),
         ('post-uninstall', None,
          "post-uninstall script (Bourne shell code)"),
-
         ('provides', None,
-         "???"),
+         "capabilities provided by this package"),
         ('requires', None,
-         "???"),
+         "capabilities required by this package"),
         ('conflicts', None,
-         "???"),
+         "capabilities which conflict with this package"),
         ('build-requires', None,
-         "???"),
+         "capabilities required to build this package"),
         ('obsoletes', None,
-         "???"),
+         "capabilities made obsolete by this package"),
 
         # Actions to take when building RPM
         ('clean', None,
@@ -93,10 +91,15 @@
          "compile with RPM_OPT_FLAGS when building from source RPM"),
         ('no-rpm-opt-flags', None,
          "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',
-                    'no-rpm-opt-flags': 'use-rpm-opt-flags'}
+                    'no-rpm-opt-flags': 'use-rpm-opt-flags',
+                    'rpm2-mode': 'rpm3-mode'}
 
                     
     def initialize_options (self):
@@ -116,10 +119,10 @@
         self.changelog = None
         self.icon = None
 
-        self.prep_cmd = None
-        self.build_cmd = None
-        self.install_cmd = None
-        self.clean_cmd = None
+        self.prep_script = None
+        self.build_script = None
+        self.install_script = None
+        self.clean_script = None
         self.pre_install = None
         self.post_install = None
         self.pre_uninstall = None
@@ -133,6 +136,7 @@
 
         self.clean = 1
         self.use_rpm_opt_flags = 1
+        self.rpm3_mode = 1
 
     # initialize_options()
 
@@ -160,31 +164,28 @@
         self.ensure_string('vendor',
                            "%s <%s>" % (self.distribution.get_contact(),
                                         self.distribution.get_contact_email()))
-        self.ensure_string('packager', self.vendor) # or nothing?
+        self.ensure_string('packager') 
         self.ensure_string_list('doc_files')
         if type(self.doc_files) is ListType:
             for readme in ('README', 'README.txt'):
                 if os.path.exists(readme) and readme not in self.doc_files:
                     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('icon')
         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:
-            def_build = 'env CFLAGS="$RPM_OPT_FLAGS" python setup.py build'
-        else:
-            def_build = 'python setup.py build'
-        self.ensure_string('build_cmd', def_build)
-        self.ensure_string('install_cmd',
-                           "python setup.py install --root=$RPM_BUILD_ROOT "
-                           "--record=INSTALLED_FILES")
-        self.ensure_string('clean_cmd',
-                           "rm -rf $RPM_BUILD_ROOT")
+        self.ensure_filename('icon')
+        
+        self.ensure_filename('prep_script')
+        self.ensure_filename('build_script')
+        self.ensure_filename('install_script')
+        self.ensure_filename('clean_script')
         self.ensure_filename('pre_install')
         self.ensure_filename('post_install')
         self.ensure_filename('pre_uninstall')
@@ -259,7 +260,11 @@
             spec_dir = "dist"
             self.mkpath(spec_dir)       # XXX should be configurable
         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 = {}
             for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
                 rpm_dir[d] = os.path.join(rpm_base, d)
@@ -308,8 +313,9 @@
             rpm_args.append('-bb')
         else:
             rpm_args.append('-ba')
-        rpm_args.extend(['--define',
-                         '_topdir %s/%s' % (os.getcwd(), rpm_base),])
+        if self.rpm3_mode:
+            rpm_args.extend(['--define',
+                             '_topdir %s/%s' % (os.getcwd(), rpm_base),])
         if self.clean:
             rpm_args.append('--clean')
         rpm_args.append(spec_path)
@@ -405,27 +411,43 @@
         #        ])
 
         # rpm scripts
-        for (rpm_opt, attr) in (('prep', 'prep_cmd'),
-                                ('build', 'build_cmd'),
-                                ('install', 'install_cmd'),
-                                ('clean', 'clean_cmd'),
-                                ('pre', 'pre_install'),
-                                ('post', 'post_install'),
-                                ('preun', 'pre_uninstall'),
-                                ('postun', 'post_uninstall')):
-            # XXX oops, this doesn't distinguish between "raw code"
-            # options and "script filename" options -- well, we probably
-            # should settle on one or the other, and not make the
-            # distinction!
+        # figure out default build script
+        if self.use_rpm_opt_flags:
+            def_build = 'env CFLAGS="$RPM_OPT_FLAGS" python setup.py build'
+        else:
+            def_build = 'python setup.py build'
+        # insert contents of files
+        for (rpm_opt, attr, default) in (('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)):
+            # Insert contents of file refered to, if no file is refered to
+            # use 'default' as contents of script
             val = getattr(self, attr)
-            if val:
+            if val or default:
                 spec_file.extend([
                     '',
-                    '%' + rpm_opt,
-                    val
-                    ])
+                    '%' + rpm_opt,])
+                if val:
+                    spec_file.extend(string.split(open(val, 'r').read(), '\n'))
+                else:
+                    spec_file.append(default)
 
-        
+
         # files section
         spec_file.extend([
             '',
@@ -439,12 +461,32 @@
         if self.changelog:
             spec_file.extend([
                 '',
-                '%changelog',
-                self.changelog
-                ])
+                '%changelog',])
+            spec_file.extend(self.changelog)
 
         return 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

--LQksG6bCIzRHxTLp--