Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
distutils.command.bdist_rpm.bdist_rpm Class Reference
Inheritance diagram for distutils.command.bdist_rpm.bdist_rpm:
Inheritance graph
[legend]
Collaboration diagram for distutils.command.bdist_rpm.bdist_rpm:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def initialize_options
def finalize_options
def finalize_package_data
def run

Public Attributes

 bdist_base
 rpm_base
 dist_dir
 python
 fix_python
 spec_only
 binary_only
 source_only
 use_bzip2
 distribution_name
 group
 release
 serial
 vendor
 packager
 doc_files
 changelog
 icon
 prep_script
 build_script
 install_script
 clean_script
 verify_script
 pre_install
 post_install
 pre_uninstall
 post_uninstall
 prep
 provides
 requires
 conflicts
 build_requires
 obsoletes
 keep_temp
 use_rpm_opt_flags
 rpm3_mode
 no_autoreq
 force_arch
 quiet

Static Public Attributes

string description = "create an RPM distribution"
list user_options
list boolean_options
dictionary negative_opt

Private Member Functions

def _dist_path
def _make_spec_file
def _format_changelog

Detailed Description

Definition at line 15 of file bdist_rpm.py.


Member Function Documentation

def distutils.command.bdist_rpm.bdist_rpm._dist_path (   self,
  path 
) [private]

Definition at line 379 of file bdist_rpm.py.

00379 
00380     def _dist_path(self, path):
00381         return os.path.join(self.dist_dir, os.path.basename(path))

def distutils.command.bdist_rpm.bdist_rpm._format_changelog (   self,
  changelog 
) [private]
Format the changelog correctly and convert it to a list of strings

Definition at line 535 of file bdist_rpm.py.

00535 
00536     def _format_changelog(self, changelog):
00537         """Format the changelog correctly and convert it to a list of strings
00538         """
00539         if not changelog:
00540             return changelog
00541         new_changelog = []
00542         for line in changelog.strip().split('\n'):
00543             line = line.strip()
00544             if line[0] == '*':
00545                 new_changelog.extend(['', line])
00546             elif line[0] == '-':
00547                 new_changelog.append(line)
00548             else:
00549                 new_changelog.append('  ' + line)
00550 
00551         # strip trailing newline inserted by first changelog entry
00552         if not new_changelog[0]:
00553             del new_changelog[0]
00554 
00555         return new_changelog

Here is the call graph for this function:

Here is the caller graph for this function:

Generate the text of an RPM spec file and return it as a
list of strings (one per line).

Definition at line 382 of file bdist_rpm.py.

00382 
00383     def _make_spec_file(self):
00384         """Generate the text of an RPM spec file and return it as a
00385         list of strings (one per line).
00386         """
00387         # definitions and headers
00388         spec_file = [
00389             '%define name ' + self.distribution.get_name(),
00390             '%define version ' + self.distribution.get_version().replace('-','_'),
00391             '%define unmangled_version ' + self.distribution.get_version(),
00392             '%define release ' + self.release.replace('-','_'),
00393             '',
00394             'Summary: ' + self.distribution.get_description(),
00395             ]
00396 
00397         # put locale summaries into spec file
00398         # XXX not supported for now (hard to put a dictionary
00399         # in a config file -- arg!)
00400         #for locale in self.summaries.keys():
00401         #    spec_file.append('Summary(%s): %s' % (locale,
00402         #                                          self.summaries[locale]))
00403 
00404         spec_file.extend([
00405             'Name: %{name}',
00406             'Version: %{version}',
00407             'Release: %{release}',])
00408 
00409         # XXX yuck! this filename is available from the "sdist" command,
00410         # but only after it has run: and we create the spec file before
00411         # running "sdist", in case of --spec-only.
00412         if self.use_bzip2:
00413             spec_file.append('Source0: %{name}-%{unmangled_version}.tar.bz2')
00414         else:
00415             spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz')
00416 
00417         spec_file.extend([
00418             'License: ' + self.distribution.get_license(),
00419             'Group: ' + self.group,
00420             'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot',
00421             'Prefix: %{_prefix}', ])
00422 
00423         if not self.force_arch:
00424             # noarch if no extension modules
00425             if not self.distribution.has_ext_modules():
00426                 spec_file.append('BuildArch: noarch')
00427         else:
00428             spec_file.append( 'BuildArch: %s' % self.force_arch )
00429 
00430         for field in ('Vendor',
00431                       'Packager',
00432                       'Provides',
00433                       'Requires',
00434                       'Conflicts',
00435                       'Obsoletes',
00436                       ):
00437             val = getattr(self, field.lower())
00438             if isinstance(val, list):
00439                 spec_file.append('%s: %s' % (field, ' '.join(val)))
00440             elif val is not None:
00441                 spec_file.append('%s: %s' % (field, val))
00442 
00443 
00444         if self.distribution.get_url() != 'UNKNOWN':
00445             spec_file.append('Url: ' + self.distribution.get_url())
00446 
00447         if self.distribution_name:
00448             spec_file.append('Distribution: ' + self.distribution_name)
00449 
00450         if self.build_requires:
00451             spec_file.append('BuildRequires: ' +
00452                              ' '.join(self.build_requires))
00453 
00454         if self.icon:
00455             spec_file.append('Icon: ' + os.path.basename(self.icon))
00456 
00457         if self.no_autoreq:
00458             spec_file.append('AutoReq: 0')
00459 
00460         spec_file.extend([
00461             '',
00462             '%description',
00463             self.distribution.get_long_description()
00464             ])
00465 
00466         # put locale descriptions into spec file
00467         # XXX again, suppressed because config file syntax doesn't
00468         # easily support this ;-(
00469         #for locale in self.descriptions.keys():
00470         #    spec_file.extend([
00471         #        '',
00472         #        '%description -l ' + locale,
00473         #        self.descriptions[locale],
00474         #        ])
00475 
00476         # rpm scripts
00477         # figure out default build script
00478         def_setup_call = "%s %s" % (self.python,os.path.basename(sys.argv[0]))
00479         def_build = "%s build" % def_setup_call
00480         if self.use_rpm_opt_flags:
00481             def_build = 'env CFLAGS="$RPM_OPT_FLAGS" ' + def_build
00482 
00483         # insert contents of files
00484 
00485         # XXX this is kind of misleading: user-supplied options are files
00486         # that we open and interpolate into the spec file, but the defaults
00487         # are just text that we drop in as-is.  Hmmm.
00488 
00489         install_cmd = ('%s install -O1 --root=$RPM_BUILD_ROOT '
00490                        '--record=INSTALLED_FILES') % def_setup_call
00491 
00492         script_options = [
00493             ('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"),
00494             ('build', 'build_script', def_build),
00495             ('install', 'install_script', install_cmd),
00496             ('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"),
00497             ('verifyscript', 'verify_script', None),
00498             ('pre', 'pre_install', None),
00499             ('post', 'post_install', None),
00500             ('preun', 'pre_uninstall', None),
00501             ('postun', 'post_uninstall', None),
00502         ]
00503 
00504         for (rpm_opt, attr, default) in script_options:
00505             # Insert contents of file referred to, if no file is referred to
00506             # use 'default' as contents of script
00507             val = getattr(self, attr)
00508             if val or default:
00509                 spec_file.extend([
00510                     '',
00511                     '%' + rpm_opt,])
00512                 if val:
00513                     spec_file.extend(open(val, 'r').read().split('\n'))
00514                 else:
00515                     spec_file.append(default)
00516 
00517 
00518         # files section
00519         spec_file.extend([
00520             '',
00521             '%files -f INSTALLED_FILES',
00522             '%defattr(-,root,root)',
00523             ])
00524 
00525         if self.doc_files:
00526             spec_file.append('%doc ' + ' '.join(self.doc_files))
00527 
00528         if self.changelog:
00529             spec_file.extend([
00530                 '',
00531                 '%changelog',])
00532             spec_file.extend(self.changelog)
00533 
00534         return spec_file

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 181 of file bdist_rpm.py.

00181 
00182     def finalize_options(self):
00183         self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
00184         if self.rpm_base is None:
00185             if not self.rpm3_mode:
00186                 raise DistutilsOptionError(
00187                       "you must specify --rpm-base in RPM 2 mode")
00188             self.rpm_base = os.path.join(self.bdist_base, "rpm")
00189 
00190         if self.python is None:
00191             if self.fix_python:
00192                 self.python = sys.executable
00193             else:
00194                 self.python = "python"
00195         elif self.fix_python:
00196             raise DistutilsOptionError(
00197                   "--python and --fix-python are mutually exclusive options")
00198 
00199         if os.name != 'posix':
00200             raise DistutilsPlatformError("don't know how to create RPM "
00201                    "distributions on platform %s" % os.name)
00202         if self.binary_only and self.source_only:
00203             raise DistutilsOptionError(
00204                   "cannot supply both '--source-only' and '--binary-only'")
00205 
00206         # don't pass CFLAGS to pure python distributions
00207         if not self.distribution.has_ext_modules():
00208             self.use_rpm_opt_flags = 0
00209 
00210         self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
00211         self.finalize_package_data()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 212 of file bdist_rpm.py.

00212 
00213     def finalize_package_data(self):
00214         self.ensure_string('group', "Development/Libraries")
00215         self.ensure_string('vendor',
00216                            "%s <%s>" % (self.distribution.get_contact(),
00217                                         self.distribution.get_contact_email()))
00218         self.ensure_string('packager')
00219         self.ensure_string_list('doc_files')
00220         if isinstance(self.doc_files, list):
00221             for readme in ('README', 'README.txt'):
00222                 if os.path.exists(readme) and readme not in self.doc_files:
00223                     self.doc_files.append(readme)
00224 
00225         self.ensure_string('release', "1")
00226         self.ensure_string('serial')   # should it be an int?
00227 
00228         self.ensure_string('distribution_name')
00229 
00230         self.ensure_string('changelog')
00231           # Format changelog correctly
00232         self.changelog = self._format_changelog(self.changelog)
00233 
00234         self.ensure_filename('icon')
00235 
00236         self.ensure_filename('prep_script')
00237         self.ensure_filename('build_script')
00238         self.ensure_filename('install_script')
00239         self.ensure_filename('clean_script')
00240         self.ensure_filename('verify_script')
00241         self.ensure_filename('pre_install')
00242         self.ensure_filename('post_install')
00243         self.ensure_filename('pre_uninstall')
00244         self.ensure_filename('post_uninstall')
00245 
00246         # XXX don't forget we punted on summaries and descriptions -- they
00247         # should be handled here eventually!
00248 
00249         # Now *this* is some meta-data that belongs in the setup script...
00250         self.ensure_string_list('provides')
00251         self.ensure_string_list('requires')
00252         self.ensure_string_list('conflicts')
00253         self.ensure_string_list('build_requires')
00254         self.ensure_string_list('obsoletes')
00255 
00256         self.ensure_string('force_arch')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 136 of file bdist_rpm.py.

00136 
00137     def initialize_options(self):
00138         self.bdist_base = None
00139         self.rpm_base = None
00140         self.dist_dir = None
00141         self.python = None
00142         self.fix_python = None
00143         self.spec_only = None
00144         self.binary_only = None
00145         self.source_only = None
00146         self.use_bzip2 = None
00147 
00148         self.distribution_name = None
00149         self.group = None
00150         self.release = None
00151         self.serial = None
00152         self.vendor = None
00153         self.packager = None
00154         self.doc_files = None
00155         self.changelog = None
00156         self.icon = None
00157 
00158         self.prep_script = None
00159         self.build_script = None
00160         self.install_script = None
00161         self.clean_script = None
00162         self.verify_script = None
00163         self.pre_install = None
00164         self.post_install = None
00165         self.pre_uninstall = None
00166         self.post_uninstall = None
00167         self.prep = None
00168         self.provides = None
00169         self.requires = None
00170         self.conflicts = None
00171         self.build_requires = None
00172         self.obsoletes = None
00173 
00174         self.keep_temp = 0
00175         self.use_rpm_opt_flags = 1
00176         self.rpm3_mode = 1
00177         self.no_autoreq = 0
00178 
00179         self.force_arch = None
00180         self.quiet = 0

Definition at line 257 of file bdist_rpm.py.

00257 
00258     def run(self):
00259         if DEBUG:
00260             print("before _get_package_data():")
00261             print("vendor =", self.vendor)
00262             print("packager =", self.packager)
00263             print("doc_files =", self.doc_files)
00264             print("changelog =", self.changelog)
00265 
00266         # make directories
00267         if self.spec_only:
00268             spec_dir = self.dist_dir
00269             self.mkpath(spec_dir)
00270         else:
00271             rpm_dir = {}
00272             for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
00273                 rpm_dir[d] = os.path.join(self.rpm_base, d)
00274                 self.mkpath(rpm_dir[d])
00275             spec_dir = rpm_dir['SPECS']
00276 
00277         # Spec file goes into 'dist_dir' if '--spec-only specified',
00278         # build/rpm.<plat> otherwise.
00279         spec_path = os.path.join(spec_dir,
00280                                  "%s.spec" % self.distribution.get_name())
00281         self.execute(write_file,
00282                      (spec_path,
00283                       self._make_spec_file()),
00284                      "writing '%s'" % spec_path)
00285 
00286         if self.spec_only: # stop if requested
00287             return
00288 
00289         # Make a source distribution and copy to SOURCES directory with
00290         # optional icon.
00291         saved_dist_files = self.distribution.dist_files[:]
00292         sdist = self.reinitialize_command('sdist')
00293         if self.use_bzip2:
00294             sdist.formats = ['bztar']
00295         else:
00296             sdist.formats = ['gztar']
00297         self.run_command('sdist')
00298         self.distribution.dist_files = saved_dist_files
00299 
00300         source = sdist.get_archive_files()[0]
00301         source_dir = rpm_dir['SOURCES']
00302         self.copy_file(source, source_dir)
00303 
00304         if self.icon:
00305             if os.path.exists(self.icon):
00306                 self.copy_file(self.icon, source_dir)
00307             else:
00308                 raise DistutilsFileError(
00309                       "icon file '%s' does not exist" % self.icon)
00310 
00311         # build package
00312         log.info("building RPMs")
00313         rpm_cmd = ['rpm']
00314         if os.path.exists('/usr/bin/rpmbuild') or \
00315            os.path.exists('/bin/rpmbuild'):
00316             rpm_cmd = ['rpmbuild']
00317 
00318         if self.source_only: # what kind of RPMs?
00319             rpm_cmd.append('-bs')
00320         elif self.binary_only:
00321             rpm_cmd.append('-bb')
00322         else:
00323             rpm_cmd.append('-ba')
00324         if self.rpm3_mode:
00325             rpm_cmd.extend(['--define',
00326                              '_topdir %s' % os.path.abspath(self.rpm_base)])
00327         if not self.keep_temp:
00328             rpm_cmd.append('--clean')
00329 
00330         if self.quiet:
00331             rpm_cmd.append('--quiet')
00332 
00333         rpm_cmd.append(spec_path)
00334         # Determine the binary rpm names that should be built out of this spec
00335         # file
00336         # Note that some of these may not be really built (if the file
00337         # list is empty)
00338         nvr_string = "%{name}-%{version}-%{release}"
00339         src_rpm = nvr_string + ".src.rpm"
00340         non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
00341         q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % (
00342             src_rpm, non_src_rpm, spec_path)
00343 
00344         out = os.popen(q_cmd)
00345         try:
00346             binary_rpms = []
00347             source_rpm = None
00348             while True:
00349                 line = out.readline()
00350                 if not line:
00351                     break
00352                 l = line.strip().split()
00353                 assert(len(l) == 2)
00354                 binary_rpms.append(l[1])
00355                 # The source rpm is named after the first entry in the spec file
00356                 if source_rpm is None:
00357                     source_rpm = l[0]
00358 
00359             status = out.close()
00360             if status:
00361                 raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))
00362 
00363         finally:
00364             out.close()
00365 
00366         self.spawn(rpm_cmd)
00367 
00368         if not self.dry_run:
00369             if not self.binary_only:
00370                 srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
00371                 assert(os.path.exists(srpm))
00372                 self.move_file(srpm, self.dist_dir)
00373 
00374             if not self.source_only:
00375                 for rpm in binary_rpms:
00376                     rpm = os.path.join(rpm_dir['RPMS'], rpm)
00377                     if os.path.exists(rpm):
00378                         self.move_file(rpm, self.dist_dir)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 137 of file bdist_rpm.py.

Definition at line 143 of file bdist_rpm.py.

Initial value:
['keep-temp', 'use-rpm-opt-flags', 'rpm3-mode',
                       'no-autoreq', 'quiet']

Definition at line 128 of file bdist_rpm.py.

Definition at line 170 of file bdist_rpm.py.

Definition at line 158 of file bdist_rpm.py.

Definition at line 154 of file bdist_rpm.py.

Definition at line 160 of file bdist_rpm.py.

Definition at line 169 of file bdist_rpm.py.

string distutils.command.bdist_rpm.bdist_rpm.description = "create an RPM distribution" [static]

Definition at line 17 of file bdist_rpm.py.

Definition at line 139 of file bdist_rpm.py.

Definition at line 147 of file bdist_rpm.py.

Definition at line 153 of file bdist_rpm.py.

Definition at line 141 of file bdist_rpm.py.

Definition at line 178 of file bdist_rpm.py.

Definition at line 148 of file bdist_rpm.py.

Definition at line 155 of file bdist_rpm.py.

Definition at line 159 of file bdist_rpm.py.

Definition at line 173 of file bdist_rpm.py.

Initial value:
{'no-keep-temp': 'keep-temp',
                    'no-rpm-opt-flags': 'use-rpm-opt-flags',
                    'rpm2-mode': 'rpm3-mode'}

Definition at line 131 of file bdist_rpm.py.

Definition at line 176 of file bdist_rpm.py.

Definition at line 171 of file bdist_rpm.py.

Definition at line 152 of file bdist_rpm.py.

Definition at line 163 of file bdist_rpm.py.

Definition at line 165 of file bdist_rpm.py.

Definition at line 162 of file bdist_rpm.py.

Definition at line 164 of file bdist_rpm.py.

Definition at line 166 of file bdist_rpm.py.

Definition at line 157 of file bdist_rpm.py.

Definition at line 167 of file bdist_rpm.py.

Definition at line 140 of file bdist_rpm.py.

Definition at line 179 of file bdist_rpm.py.

Definition at line 149 of file bdist_rpm.py.

Definition at line 168 of file bdist_rpm.py.

Definition at line 175 of file bdist_rpm.py.

Definition at line 138 of file bdist_rpm.py.

Definition at line 150 of file bdist_rpm.py.

Definition at line 144 of file bdist_rpm.py.

Definition at line 142 of file bdist_rpm.py.

Definition at line 145 of file bdist_rpm.py.

Definition at line 174 of file bdist_rpm.py.

Definition at line 19 of file bdist_rpm.py.

Definition at line 151 of file bdist_rpm.py.

Definition at line 161 of file bdist_rpm.py.


The documentation for this class was generated from the following file: