Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 1 | """distutils.command.bdist_rpm |
| 2 | |
| 3 | Implements the Distutils 'bdist_rpm' command (create RPM source and binary |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 4 | distributions).""" |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 5 | |
| 6 | # created 2000/04/25, by Harry Henry Gebel |
| 7 | |
| 8 | __revision__ = "$Id$" |
| 9 | |
Greg Ward | 4227dc1 | 2000-06-04 14:20:57 +0000 | [diff] [blame] | 10 | import os, string |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 11 | from types import * |
Greg Ward | efbd071 | 2000-06-02 02:01:51 +0000 | [diff] [blame] | 12 | from distutils.core import Command, DEBUG |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 13 | from distutils.util import get_platform, write_file |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 14 | from distutils.errors import * |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 15 | |
| 16 | class bdist_rpm (Command): |
| 17 | |
| 18 | description = "create an RPM distribution" |
| 19 | |
| 20 | user_options = [ |
Greg Ward | 7ce6d07 | 2000-06-04 15:30:35 +0000 | [diff] [blame] | 21 | ('bdist-base=', None, |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 22 | "base directory for creating built distributions"), |
Greg Ward | 7ce6d07 | 2000-06-04 15:30:35 +0000 | [diff] [blame] | 23 | ('rpm-base=', None, |
| 24 | "base directory for creating RPMs (defaults to \"rpm\" under " |
| 25 | "--bdist-base; must be specified for RPM 2)"), |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 26 | ('spec-only', None, |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 27 | "only regenerate spec file"), |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 28 | ('source-only', None, |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 29 | "only generate source RPM"), |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 30 | ('binary-only', None, |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 31 | "only generate binary RPM"), |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 32 | ('use-bzip2', None, |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 33 | "use bzip2 instead of gzip to create source distribution"), |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 34 | |
| 35 | # More meta-data: too RPM-specific to put in the setup script, |
| 36 | # but needs to go in the .spec file -- so we make these options |
| 37 | # to "bdist_rpm". The idea is that packagers would put this |
| 38 | # info in setup.cfg, although they are of course free to |
| 39 | # supply it on the command line. |
| 40 | ('distribution-name', None, |
| 41 | "name of the (Linux) distribution name to which this " |
| 42 | "RPM applies (*not* the name of the module distribution!)"), |
| 43 | ('group', None, |
| 44 | "package classification [default: \"Development/Libraries\"]"), |
| 45 | ('release', None, |
| 46 | "RPM release number"), |
| 47 | ('serial', None, |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 48 | "RPM serial number"), |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 49 | ('vendor', None, |
| 50 | "RPM \"vendor\" (eg. \"Joe Blow <joe@example.com>\") " |
| 51 | "[default: maintainer or author from setup script]"), |
| 52 | ('packager', None, |
| 53 | "RPM packager (eg. \"Jane Doe <jane@example.net>\")" |
| 54 | "[default: vendor]"), |
| 55 | ('doc-files', None, |
| 56 | "list of documentation files (space or comma-separated)"), |
| 57 | ('changelog', None, |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 58 | "path to RPM changelog"), |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 59 | ('icon', None, |
| 60 | "name of icon file"), |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 61 | ('prep-script', None, |
| 62 | "pre-build script (Bourne shell code)"), |
| 63 | ('build-script', None, |
| 64 | "build script (Bourne shell code)"), |
| 65 | ('install-script', None, |
| 66 | "installation script (Bourne shell code)"), |
| 67 | ('clean-script', None, |
| 68 | "clean script (Bourne shell code)"), |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 69 | ('pre-install', None, |
| 70 | "pre-install script (Bourne shell code)"), |
| 71 | ('post-install', None, |
| 72 | "post-install script (Bourne shell code)"), |
| 73 | ('pre-uninstall', None, |
| 74 | "pre-uninstall script (Bourne shell code)"), |
| 75 | ('post-uninstall', None, |
| 76 | "post-uninstall script (Bourne shell code)"), |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 77 | ('provides', None, |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 78 | "capabilities provided by this package"), |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 79 | ('requires', None, |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 80 | "capabilities required by this package"), |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 81 | ('conflicts', None, |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 82 | "capabilities which conflict with this package"), |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 83 | ('build-requires', None, |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 84 | "capabilities required to build this package"), |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 85 | ('obsoletes', None, |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 86 | "capabilities made obsolete by this package"), |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 87 | |
| 88 | # Actions to take when building RPM |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 89 | ('clean', None, |
| 90 | "clean up RPM build directory [default]"), |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 91 | ('no-clean', None, |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 92 | "don't clean up RPM build directory"), |
| 93 | ('use-rpm-opt-flags', None, |
| 94 | "compile with RPM_OPT_FLAGS when building from source RPM"), |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 95 | ('no-rpm-opt-flags', None, |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 96 | "do not pass any RPM CFLAGS to compiler"), |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 97 | ('rpm3-mode', None, |
| 98 | "RPM 3 compatibility mode (default)"), |
| 99 | ('rpm2-mode', None, |
| 100 | "RPM 2 compatibility mode"), |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 101 | ] |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 102 | |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 103 | negative_opt = {'no-clean': 'clean', |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 104 | 'no-rpm-opt-flags': 'use-rpm-opt-flags', |
| 105 | 'rpm2-mode': 'rpm3-mode'} |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 106 | |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 107 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 108 | def initialize_options (self): |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 109 | self.bdist_base = None |
Greg Ward | 7ce6d07 | 2000-06-04 15:30:35 +0000 | [diff] [blame] | 110 | self.rpm_base = None |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 111 | self.spec_only = None |
| 112 | self.binary_only = None |
| 113 | self.source_only = None |
| 114 | self.use_bzip2 = None |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 115 | |
| 116 | self.distribution_name = None |
| 117 | self.group = None |
| 118 | self.release = None |
| 119 | self.serial = None |
| 120 | self.vendor = None |
| 121 | self.packager = None |
| 122 | self.doc_files = None |
| 123 | self.changelog = None |
| 124 | self.icon = None |
| 125 | |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 126 | self.prep_script = None |
| 127 | self.build_script = None |
| 128 | self.install_script = None |
| 129 | self.clean_script = None |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 130 | self.pre_install = None |
| 131 | self.post_install = None |
| 132 | self.pre_uninstall = None |
| 133 | self.post_uninstall = None |
| 134 | self.prep = None |
| 135 | self.provides = None |
| 136 | self.requires = None |
| 137 | self.conflicts = None |
| 138 | self.build_requires = None |
| 139 | self.obsoletes = None |
| 140 | |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 141 | self.clean = 1 |
| 142 | self.use_rpm_opt_flags = 1 |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 143 | self.rpm3_mode = 1 |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 144 | |
| 145 | # initialize_options() |
| 146 | |
| 147 | |
| 148 | def finalize_options (self): |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 149 | self.set_undefined_options('bdist', ('bdist_base', 'bdist_base')) |
Greg Ward | 7ce6d07 | 2000-06-04 15:30:35 +0000 | [diff] [blame] | 150 | if self.rpm_base is None: |
| 151 | if not self.rpm3_mode: |
| 152 | raise DistutilsOptionError, \ |
| 153 | "you must specify --rpm-base in RPM 2 mode" |
| 154 | self.rpm_base = os.path.join(self.bdist_base, "rpm") |
| 155 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 156 | if os.name != 'posix': |
| 157 | raise DistutilsPlatformError, \ |
| 158 | ("don't know how to create RPM " |
| 159 | "distributions on platform %s" % os.name) |
| 160 | if self.binary_only and self.source_only: |
| 161 | raise DistutilsOptionsError, \ |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 162 | "cannot supply both '--source-only' and '--binary-only'" |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 163 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 164 | # don't pass CFLAGS to pure python distributions |
| 165 | if not self.distribution.has_ext_modules(): |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 166 | self.use_rpm_opt_flags = 0 |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 167 | |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 168 | self.finalize_package_data() |
| 169 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 170 | # finalize_options() |
| 171 | |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 172 | def finalize_package_data (self): |
| 173 | self.ensure_string('group', "Development/Libraries") |
| 174 | self.ensure_string('vendor', |
| 175 | "%s <%s>" % (self.distribution.get_contact(), |
| 176 | self.distribution.get_contact_email())) |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 177 | self.ensure_string('packager') |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 178 | self.ensure_string_list('doc_files') |
| 179 | if type(self.doc_files) is ListType: |
| 180 | for readme in ('README', 'README.txt'): |
| 181 | if os.path.exists(readme) and readme not in self.doc_files: |
| 182 | self.doc.append(readme) |
| 183 | |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 184 | self.ensure_string('release', "1") |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 185 | self.ensure_string('serial') # should it be an int? |
| 186 | |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 187 | self.ensure_string('distribution_name') |
| 188 | |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 189 | self.ensure_string('changelog') |
| 190 | # Format changelog correctly |
| 191 | self.changelog = self._format_changelog(self.changelog) |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 192 | |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 193 | self.ensure_filename('icon') |
| 194 | |
| 195 | self.ensure_filename('prep_script') |
| 196 | self.ensure_filename('build_script') |
| 197 | self.ensure_filename('install_script') |
| 198 | self.ensure_filename('clean_script') |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 199 | self.ensure_filename('pre_install') |
| 200 | self.ensure_filename('post_install') |
| 201 | self.ensure_filename('pre_uninstall') |
| 202 | self.ensure_filename('post_uninstall') |
| 203 | |
| 204 | # XXX don't forget we punted on summaries and descriptions -- they |
| 205 | # should be handled here eventually! |
| 206 | |
| 207 | # Now *this* is some meta-data that belongs in the setup script... |
| 208 | self.ensure_string_list('provides') |
| 209 | self.ensure_string_list('requires') |
| 210 | self.ensure_string_list('conflicts') |
| 211 | self.ensure_string_list('build_requires') |
| 212 | self.ensure_string_list('obsoletes') |
| 213 | |
| 214 | # finalize_package_data () |
| 215 | |
| 216 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 217 | def run (self): |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 218 | |
Greg Ward | efbd071 | 2000-06-02 02:01:51 +0000 | [diff] [blame] | 219 | if DEBUG: |
| 220 | print "before _get_package_data():" |
| 221 | print "vendor =", self.vendor |
| 222 | print "packager =", self.packager |
| 223 | print "doc_files =", self.doc_files |
| 224 | print "changelog =", self.changelog |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 225 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 226 | # make directories |
| 227 | if self.spec_only: |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 228 | spec_dir = "dist" |
| 229 | self.mkpath(spec_dir) # XXX should be configurable |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 230 | else: |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 231 | rpm_dir = {} |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 232 | for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'): |
Greg Ward | 7ce6d07 | 2000-06-04 15:30:35 +0000 | [diff] [blame] | 233 | rpm_dir[d] = os.path.join(self.rpm_base, d) |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 234 | self.mkpath(rpm_dir[d]) |
| 235 | spec_dir = rpm_dir['SPECS'] |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 236 | |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 237 | # Spec file goes into 'dist' directory if '--spec-only specified', |
| 238 | # into build/rpm.<plat> otherwise. |
| 239 | spec_path = os.path.join(spec_dir, |
| 240 | "%s.spec" % self.distribution.get_name()) |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 241 | self.execute(write_file, |
| 242 | (spec_path, |
| 243 | self._make_spec_file()), |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 244 | "writing '%s'" % spec_path) |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 245 | |
| 246 | if self.spec_only: # stop if requested |
| 247 | return |
| 248 | |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 249 | # Make a source distribution and copy to SOURCES directory with |
| 250 | # optional icon. |
| 251 | sdist = self.reinitialize_command ('sdist') |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 252 | if self.use_bzip2: |
| 253 | sdist.formats = ['bztar'] |
| 254 | else: |
| 255 | sdist.formats = ['gztar'] |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 256 | self.run_command('sdist') |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 257 | |
| 258 | source = sdist.get_archive_files()[0] |
| 259 | source_dir = rpm_dir['SOURCES'] |
| 260 | self.copy_file(source, source_dir) |
| 261 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 262 | if self.icon: |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 263 | if os.path.exists(self.icon): |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 264 | self.copy_file(self.icon, source_dir) |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 265 | else: |
| 266 | raise DistutilsFileError, \ |
Greg Ward | 01a4694 | 2000-06-01 00:40:25 +0000 | [diff] [blame] | 267 | "icon file '%s' does not exist" % self.icon |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 268 | |
| 269 | |
| 270 | # build package |
| 271 | self.announce('Building RPMs') |
| 272 | rpm_args = ['rpm',] |
| 273 | if self.source_only: # what kind of RPMs? |
| 274 | rpm_args.append('-bs') |
| 275 | elif self.binary_only: |
| 276 | rpm_args.append('-bb') |
| 277 | else: |
| 278 | rpm_args.append('-ba') |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 279 | if self.rpm3_mode: |
| 280 | rpm_args.extend(['--define', |
Greg Ward | 7ce6d07 | 2000-06-04 15:30:35 +0000 | [diff] [blame] | 281 | '_topdir %s/%s' % (os.getcwd(), self.rpm_base),]) |
Greg Ward | 69413da | 2000-05-31 23:56:45 +0000 | [diff] [blame] | 282 | if self.clean: |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 283 | rpm_args.append('--clean') |
| 284 | rpm_args.append(spec_path) |
| 285 | self.spawn(rpm_args) |
| 286 | |
| 287 | # run() |
| 288 | |
| 289 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 290 | def _make_spec_file(self): |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 291 | """Generate the text of an RPM spec file and return it as a |
| 292 | list of strings (one per line). |
| 293 | """ |
| 294 | # definitions and headers |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 295 | spec_file = [ |
| 296 | '%define name ' + self.distribution.get_name(), |
| 297 | '%define version ' + self.distribution.get_version(), |
| 298 | '%define release ' + self.release, |
| 299 | '', |
| 300 | 'Summary: ' + self.distribution.get_description(), |
| 301 | ] |
| 302 | |
| 303 | # put locale summaries into spec file |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 304 | # XXX not supported for now (hard to put a dictionary |
| 305 | # in a config file -- arg!) |
| 306 | #for locale in self.summaries.keys(): |
| 307 | # spec_file.append('Summary(%s): %s' % (locale, |
| 308 | # self.summaries[locale])) |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 309 | |
| 310 | spec_file.extend([ |
| 311 | 'Name: %{name}', |
| 312 | 'Version: %{version}', |
| 313 | 'Release: %{release}',]) |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 314 | |
| 315 | # XXX yuck! this filename is available from the "sdist" command, |
| 316 | # but only after it has run: and we create the spec file before |
| 317 | # running "sdist", in case of --spec-only. |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 318 | if self.use_bzip2: |
| 319 | spec_file.append('Source0: %{name}-%{version}.tar.bz2') |
| 320 | else: |
| 321 | spec_file.append('Source0: %{name}-%{version}.tar.gz') |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 322 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 323 | spec_file.extend([ |
| 324 | 'Copyright: ' + self.distribution.get_licence(), |
| 325 | 'Group: ' + self.group, |
| 326 | 'BuildRoot: %{_tmppath}/%{name}-buildroot', |
| 327 | 'Prefix: %{_prefix}', ]) |
| 328 | |
| 329 | # noarch if no extension modules |
| 330 | if not self.distribution.has_ext_modules(): |
| 331 | spec_file.append('BuildArchitectures: noarch') |
| 332 | |
| 333 | for field in ('Vendor', |
| 334 | 'Packager', |
| 335 | 'Provides', |
| 336 | 'Requires', |
| 337 | 'Conflicts', |
| 338 | 'Obsoletes', |
| 339 | ): |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 340 | val = getattr(self, string.lower(field)) |
| 341 | if type(val) is ListType: |
| 342 | spec_file.append('%s: %s' % (field, string.join(val))) |
| 343 | elif val is not None: |
| 344 | spec_file.append('%s: %s' % (field, val)) |
| 345 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 346 | |
| 347 | if self.distribution.get_url() != 'UNKNOWN': |
| 348 | spec_file.append('Url: ' + self.distribution.get_url()) |
| 349 | |
| 350 | if self.distribution_name: |
| 351 | spec_file.append('Distribution: ' + self.distribution_name) |
| 352 | |
| 353 | if self.build_requires: |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 354 | spec_file.append('BuildRequires: ' + |
| 355 | string.join(self.build_requires)) |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 356 | |
| 357 | if self.icon: |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 358 | spec_file.append('Icon: ' + os.path.basename(self.icon)) |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 359 | |
| 360 | spec_file.extend([ |
| 361 | '', |
| 362 | '%description', |
| 363 | self.distribution.get_long_description() |
| 364 | ]) |
| 365 | |
| 366 | # put locale descriptions into spec file |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 367 | # XXX again, suppressed because config file syntax doesn't |
| 368 | # easily support this ;-( |
| 369 | #for locale in self.descriptions.keys(): |
| 370 | # spec_file.extend([ |
| 371 | # '', |
| 372 | # '%description -l ' + locale, |
| 373 | # self.descriptions[locale], |
| 374 | # ]) |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 375 | |
| 376 | # rpm scripts |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 377 | # figure out default build script |
| 378 | if self.use_rpm_opt_flags: |
| 379 | def_build = 'env CFLAGS="$RPM_OPT_FLAGS" python setup.py build' |
| 380 | else: |
| 381 | def_build = 'python setup.py build' |
| 382 | # insert contents of files |
| 383 | |
| 384 | # XXX this is kind of misleading: user-supplied options are files |
| 385 | # that we open and interpolate into the spec file, but the defaults |
| 386 | # are just text that we drop in as-is. Hmmm. |
| 387 | |
| 388 | script_options = [ |
| 389 | ('prep', 'prep_script', "%setup"), |
| 390 | ('build', 'build_script', def_build), |
| 391 | ('install', 'install_script', |
| 392 | "python setup.py install " |
| 393 | "--root=$RPM_BUILD_ROOT " |
| 394 | "--record=INSTALLED_FILES"), |
| 395 | ('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"), |
| 396 | ('pre', 'pre_install', None), |
| 397 | ('post', 'post_install', None), |
| 398 | ('preun', 'pre_uninstall', None), |
Greg Ward | 7ce6d07 | 2000-06-04 15:30:35 +0000 | [diff] [blame] | 399 | ('postun', 'post_uninstall', None), |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 400 | ] |
| 401 | |
| 402 | for (rpm_opt, attr, default) in script_options: |
| 403 | # Insert contents of file refered to, if no file is refered to |
| 404 | # use 'default' as contents of script |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 405 | val = getattr(self, attr) |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 406 | if val or default: |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 407 | spec_file.extend([ |
| 408 | '', |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 409 | '%' + rpm_opt,]) |
| 410 | if val: |
| 411 | spec_file.extend(string.split(open(val, 'r').read(), '\n')) |
| 412 | else: |
| 413 | spec_file.append(default) |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 414 | |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 415 | |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 416 | # files section |
| 417 | spec_file.extend([ |
| 418 | '', |
| 419 | '%files -f INSTALLED_FILES', |
| 420 | '%defattr(-,root,root)', |
| 421 | ]) |
| 422 | |
Greg Ward | 1259392 | 2000-06-02 01:49:58 +0000 | [diff] [blame] | 423 | if self.doc_files: |
| 424 | spec_file.append('%doc ' + string.join(self.doc_files)) |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 425 | |
| 426 | if self.changelog: |
| 427 | spec_file.extend([ |
| 428 | '', |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 429 | '%changelog',]) |
| 430 | spec_file.extend(self.changelog) |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 431 | |
| 432 | return spec_file |
| 433 | |
Greg Ward | 6739258 | 2000-06-02 01:52:04 +0000 | [diff] [blame] | 434 | # _make_spec_file () |
Gregory P. Smith | 86ee81e | 2000-05-13 03:11:40 +0000 | [diff] [blame] | 435 | |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 436 | def _format_changelog(self, changelog): |
| 437 | """Format the changelog correctly and convert it to a list of strings |
| 438 | """ |
Greg Ward | d2412a3 | 2000-06-08 14:21:23 +0000 | [diff] [blame] | 439 | if not changelog: |
| 440 | return changelog |
Greg Ward | a68c93a | 2000-06-04 15:00:34 +0000 | [diff] [blame] | 441 | new_changelog = [] |
| 442 | for line in string.split(string.strip(changelog), '\n'): |
| 443 | line = string.strip(line) |
| 444 | if line[0] == '*': |
| 445 | new_changelog.extend(['', line]) |
| 446 | elif line[0] == '-': |
| 447 | new_changelog.append(line) |
| 448 | else: |
| 449 | new_changelog.append(' ' + line) |
| 450 | |
| 451 | # strip trailing newline inserted by first changelog entry |
| 452 | if not new_changelog[0]: |
| 453 | del new_changelog[0] |
| 454 | |
| 455 | return new_changelog |
| 456 | |
| 457 | # _format_changelog() |
| 458 | |
Greg Ward | 6739258 | 2000-06-02 01:52:04 +0000 | [diff] [blame] | 459 | # class bdist_rpm |