Some far-reaching naming changes:

* Command method 'find_peer()' -> 'get_finalized_command()'
  * Command method 'run_peer()' -> 'run_command()'
Also deleted the 'get_command_option()' method from Command, and
  fixed the one place where it was used (in "bdist_dumb").
This commit is contained in:
Greg Ward 2000-05-27 17:27:23 +00:00
parent 25bfd0e8d0
commit 4fb29e55f8
11 changed files with 59 additions and 78 deletions

View file

@ -69,11 +69,11 @@ def __init__ (self, dist):
# none of that complicated bureaucracy is needed. # none of that complicated bureaucracy is needed.
self.help = 0 self.help = 0
# 'ready' records whether or not 'finalize_options()' has been # 'finalized' records whether or not 'finalize_options()' has been
# called. 'finalize_options()' itself should not pay attention to # called. 'finalize_options()' itself should not pay attention to
# this flag: it is the business of 'ensure_ready()', which always # this flag: it is the business of 'ensure_finalized()', which
# calls 'finalize_options()', to respect/update it. # always calls 'finalize_options()', to respect/update it.
self.ready = 0 self.finalized = 0
# __init__ () # __init__ ()
@ -89,10 +89,10 @@ def __getattr__ (self, attr):
raise AttributeError, attr raise AttributeError, attr
def ensure_ready (self): def ensure_finalized (self):
if not self.ready: if not self.finalized:
self.finalize_options () self.finalize_options ()
self.ready = 1 self.finalized = 1
# Subclasses must define: # Subclasses must define:
@ -184,32 +184,24 @@ def set_undefined_options (self, src_cmd, *option_pairs):
# Option_pairs: list of (src_option, dst_option) tuples # Option_pairs: list of (src_option, dst_option) tuples
src_cmd_obj = self.distribution.get_command_obj (src_cmd) src_cmd_obj = self.distribution.get_command_obj (src_cmd)
src_cmd_obj.ensure_ready () src_cmd_obj.ensure_finalized ()
for (src_option, dst_option) in option_pairs: for (src_option, dst_option) in option_pairs:
if getattr (self, dst_option) is None: if getattr (self, dst_option) is None:
setattr (self, dst_option, setattr (self, dst_option,
getattr (src_cmd_obj, src_option)) getattr (src_cmd_obj, src_option))
def find_peer (self, command, create=1): def get_finalized_command (self, command, create=1):
"""Wrapper around Distribution's 'get_command_obj()' method: """Wrapper around Distribution's 'get_command_obj()' method:
find (create if necessary and 'create' is true) the command find (create if necessary and 'create' is true) the command
object for 'command'..""" object for 'command'.."""
cmd_obj = self.distribution.get_command_obj (command, create) cmd_obj = self.distribution.get_command_obj (command, create)
cmd_obj.ensure_ready () cmd_obj.ensure_finalized ()
return cmd_obj return cmd_obj
def get_peer_option (self, command, option): def run_command (self, command):
"""Find or create the command object for 'command', and return
its 'option' option."""
cmd_obj = self.find_peer (command)
return getattr(cmd_obj, option)
def run_peer (self, command):
"""Run some other command: uses the 'run_command()' method of """Run some other command: uses the 'run_command()' method of
Distribution, which creates the command object if necessary Distribution, which creates the command object if necessary
and then invokes its 'run()' method.""" and then invokes its 'run()' method."""

View file

@ -53,7 +53,7 @@ def finalize_options (self):
# temporary directories (eg. we'll probably have # temporary directories (eg. we'll probably have
# "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.) # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
if self.bdist_base is None: if self.bdist_base is None:
build_base = self.find_peer('build').build_base build_base = self.get_finalized_command('build').build_base
plat = get_platform() plat = get_platform()
self.bdist_base = os.path.join (build_base, 'bdist.' + plat) self.bdist_base = os.path.join (build_base, 'bdist.' + plat)
@ -79,9 +79,9 @@ def run (self):
"invalid archive format '%s'" % self.format "invalid archive format '%s'" % self.format
if cmd_name not in self.no_format_option: if cmd_name not in self.no_format_option:
sub_cmd = self.find_peer (cmd_name) sub_cmd = self.get_finalized_command (cmd_name)
sub_cmd.format = self.format sub_cmd.format = self.format
self.run_peer (cmd_name) self.run_command (cmd_name)
# run() # run()

View file

@ -40,7 +40,7 @@ def initialize_options (self):
def finalize_options (self): def finalize_options (self):
if self.bdist_dir is None: if self.bdist_dir is None:
bdist_base = self.get_peer_option('bdist', 'bdist_base') bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'dumb') self.bdist_dir = os.path.join(bdist_base, 'dumb')
if self.format is None: if self.format is None:
@ -56,10 +56,10 @@ def finalize_options (self):
def run (self): def run (self):
self.run_peer ('build') self.run_command ('build')
# XXX don't use 'self.find_peer()', because it always runs # XXX don't use 'self.get_finalized_command()', because it always runs
# 'ensure_ready()' on the command object; we explictly want a # 'ensure_finalized()' on the command object; we explictly want a
# command object that has *not* been finalized, so we can set # command object that has *not* been finalized, so we can set
# options on it! (The option we set, 'root', is so that we can do # options on it! (The option we set, 'root', is so that we can do
# a proper "fake install" using this install command object.) # a proper "fake install" using this install command object.)
@ -67,7 +67,7 @@ def run (self):
install.root = self.bdist_dir install.root = self.bdist_dir
self.announce ("installing to %s" % self.bdist_dir) self.announce ("installing to %s" % self.bdist_dir)
install.ensure_ready() install.ensure_finalized()
install.run() install.run()
# And make an archive relative to the root of the # And make an archive relative to the root of the

View file

@ -1,20 +1,17 @@
"""distutils.command.bdist_rpm """distutils.command.bdist_rpm
Implements the Distutils 'bdist_rpm' command (create RPM source and binary Implements the Distutils 'bdist_rpm' command (create RPM source and binary
distributions.""" distributions)."""
# created 2000/04/25, by Harry Henry Gebel # created 2000/04/25, by Harry Henry Gebel
__revision__ = "$Id$" __revision__ = "$Id$"
from os.path import exists, basename import os, string
import os from types import *
from distutils.core import Command from distutils.core import Command
from distutils.util import mkpath, write_file, copy_file from distutils.util import mkpath, write_file, copy_file
from distutils.errors import * from distutils.errors import *
from string import join, lower
from types import StringType, DictType, LongType, FloatType, IntType, \
ListType, TupleType
class bdist_rpm (Command): class bdist_rpm (Command):
@ -68,23 +65,15 @@ def run (self):
# make directories # make directories
if self.spec_only: if self.spec_only:
self.execute(mkpath, ('redhat',), "Created './redhat' directory") self.mkpath('redhat')
else: else:
self.execute(mkpath, ('build/rpm/SOURCES',), for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
"Created RPM source directory") self.mkpath(os.path.join('build/rpm', d))
self.execute(mkpath, ('build/rpm/SPECS',),
"Created RPM source directory")
self.execute(mkpath, ('build/rpm/BUILD',),
"Created RPM source directory")
self.execute(mkpath, ('build/rpm/RPMS',),
"Created RPM source directory")
self.execute(mkpath, ('build/rpm/SRPMS',),
"Created RPM source directory")
# spec file goes into .redhat directory if '--spec-only specified', # spec file goes into .redhat directory if '--spec-only specified',
# into build/rpm/spec otherwisu # into build/rpm/spec otherwise
if self.spec_only: if self.spec_only:
spec_path = './redhat/%s.spec' % self.distribution.get_name() spec_path = 'redhat/%s.spec' % self.distribution.get_name()
else: else:
spec_path = ('build/rpm/SPECS/%s.spec' % spec_path = ('build/rpm/SPECS/%s.spec' %
self.distribution.get_name()) self.distribution.get_name())
@ -98,12 +87,12 @@ def run (self):
# make a source distribution and copy to SOURCES directory with # make a source distribution and copy to SOURCES directory with
# optional icon # optional icon
sdist = self.find_peer ('sdist') sdist = self.get_finalized_command ('sdist')
if self.use_bzip2: if self.use_bzip2:
sdist.formats = ['bztar'] sdist.formats = ['bztar']
else: else:
sdist.formats = ['gztar'] sdist.formats = ['gztar']
self.run_peer('sdist') self.run_command('sdist')
if self.use_bzip2: if self.use_bzip2:
source = self.distribution.get_fullname() + '.tar.bz2' source = self.distribution.get_fullname() + '.tar.bz2'
else: else:
@ -111,7 +100,7 @@ def run (self):
self.execute(copy_file, (source, 'build/rpm/SOURCES'), self.execute(copy_file, (source, 'build/rpm/SOURCES'),
'Copying source distribution to SOURCES') 'Copying source distribution to SOURCES')
if self.icon: if self.icon:
if exists(self.icon): if os.path.exists(self.icon):
self.execute(copy_file, (self.icon, 'build/rpm/SOURCES'), self.execute(copy_file, (self.icon, 'build/rpm/SOURCES'),
'Copying icon to SOURCES') 'Copying icon to SOURCES')
else: else:
@ -144,10 +133,12 @@ def _get_package_data(self):
DistributionMetadata class, then from the package_data file, which is DistributionMetadata class, then from the package_data file, which is
Python code read with execfile() ''' Python code read with execfile() '''
from string import join
package_type = 'rpm' package_type = 'rpm'
# read in package data, if any # read in package data, if any
if exists('package_data'): if os.path.exists('package_data'):
try: try:
exec(open('package_data')) exec(open('package_data'))
except: except:
@ -195,7 +186,7 @@ def _get_package_data(self):
self.doc = self._check_string_list('doc') self.doc = self._check_string_list('doc')
if type(self.doc) == ListType: if type(self.doc) == ListType:
for readme in ('README', 'README.txt'): for readme in ('README', 'README.txt'):
if exists(readme) and readme not in self.doc: if os.path.exists(readme) and readme not in self.doc:
self.doc.append(readme) self.doc.append(readme)
self.doc = join(self.doc) self.doc = join(self.doc)
self.provides = join(self._check_string_list('provides')) self.provides = join(self._check_string_list('provides'))
@ -246,9 +237,9 @@ def _make_spec_file(self):
'Conflicts', 'Conflicts',
'Obsoletes', 'Obsoletes',
): ):
if getattr(self, lower(field)): if getattr(self, string.lower(field)):
spec_file.append('%s: %s' % (field, getattr(self, spec_file.append('%s: %s' %
lower(field)))) (field, getattr(self, string.lower(field))))
if self.distribution.get_url() != 'UNKNOWN': if self.distribution.get_url() != 'UNKNOWN':
spec_file.append('Url: ' + self.distribution.get_url()) spec_file.append('Url: ' + self.distribution.get_url())
@ -260,7 +251,7 @@ def _make_spec_file(self):
spec_file.append('BuildRequires: ' + self.build_requires) spec_file.append('BuildRequires: ' + self.build_requires)
if self.icon: if self.icon:
spec_file.append('Icon: ' + basename(self.icon)) spec_file.append('Icon: ' + os.path.basename(self.icon))
spec_file.extend([ spec_file.extend([
'', '',
@ -388,5 +379,3 @@ def _check_string_list(self, var_name, default_value = []):
'list or tuple of strings' % var_name) 'list or tuple of strings' % var_name)
else: else:
return default_value return default_value
# class bdist_rpm

View file

@ -92,20 +92,20 @@ def run (self):
# Invoke the 'build_py' command to "build" pure Python modules # Invoke the 'build_py' command to "build" pure Python modules
# (ie. copy 'em into the build tree) # (ie. copy 'em into the build tree)
if self.distribution.has_pure_modules(): if self.distribution.has_pure_modules():
self.run_peer ('build_py') self.run_command ('build_py')
# Build any standalone C libraries next -- they're most likely to # Build any standalone C libraries next -- they're most likely to
# be needed by extension modules, so obviously have to be done # be needed by extension modules, so obviously have to be done
# first! # first!
if self.distribution.has_c_libraries(): if self.distribution.has_c_libraries():
self.run_peer ('build_clib') self.run_command ('build_clib')
# And now 'build_ext' -- compile extension modules and put them # And now 'build_ext' -- compile extension modules and put them
# into the build tree # into the build tree
if self.distribution.has_ext_modules(): if self.distribution.has_ext_modules():
self.run_peer ('build_ext') self.run_command ('build_ext')
if self.distribution.has_scripts(): if self.distribution.has_scripts():
self.run_peer ('build_scripts') self.run_command ('build_scripts')
# class build # class build

View file

@ -167,7 +167,7 @@ def run (self):
# directory where we put them is in the library search path for # directory where we put them is in the library search path for
# linking extensions. # linking extensions.
if self.distribution.has_c_libraries(): if self.distribution.has_c_libraries():
build_clib = self.find_peer ('build_clib') build_clib = self.get_finalized_command ('build_clib')
self.libraries.extend (build_clib.get_library_names() or []) self.libraries.extend (build_clib.get_library_names() or [])
self.library_dirs.append (build_clib.build_clib) self.library_dirs.append (build_clib.build_clib)
@ -294,7 +294,7 @@ def build_extensions (self):
package = string.join (modpath[0:-1], '.') package = string.join (modpath[0:-1], '.')
base = modpath[-1] base = modpath[-1]
build_py = self.find_peer ('build_py') build_py = self.get_finalized_command ('build_py')
package_dir = build_py.get_package_dir (package) package_dir = build_py.get_package_dir (package)
ext_filename = os.path.join (package_dir, ext_filename = os.path.join (package_dir,
self.get_ext_filename(base)) self.get_ext_filename(base))

View file

@ -454,11 +454,11 @@ def run (self):
# Obviously have to build before we can install # Obviously have to build before we can install
if not self.skip_build: if not self.skip_build:
self.run_peer ('build') self.run_command ('build')
# Run all sub-commands (at least those that need to be run) # Run all sub-commands (at least those that need to be run)
for cmd_name in self.get_sub_commands(): for cmd_name in self.get_sub_commands():
self.run_peer (cmd_name) self.run_command (cmd_name)
if self.path_file: if self.path_file:
self.create_path_file () self.create_path_file ()
@ -507,7 +507,7 @@ def get_outputs (self):
# get the outputs of all its sub-commands. # get the outputs of all its sub-commands.
outputs = [] outputs = []
for cmd_name in self.get_sub_commands(): for cmd_name in self.get_sub_commands():
cmd = self.find_peer (cmd_name) cmd = self.get_finalized_command (cmd_name)
outputs.extend (cmd.get_outputs()) outputs.extend (cmd.get_outputs())
return outputs return outputs
@ -517,7 +517,7 @@ def get_inputs (self):
# XXX gee, this looks familiar ;-( # XXX gee, this looks familiar ;-(
inputs = [] inputs = []
for cmd_name in self.get_sub_commands(): for cmd_name in self.get_sub_commands():
cmd = self.find_peer (cmd_name) cmd = self.get_finalized_command (cmd_name)
inputs.extend (cmd.get_inputs()) inputs.extend (cmd.get_inputs())
return inputs return inputs

View file

@ -46,9 +46,9 @@ def run (self):
# Make sure we have built everything we need first # Make sure we have built everything we need first
if not self.skip_build: if not self.skip_build:
if self.distribution.has_pure_modules(): if self.distribution.has_pure_modules():
self.run_peer ('build_py') self.run_command ('build_py')
if self.distribution.has_ext_modules(): if self.distribution.has_ext_modules():
self.run_peer ('build_ext') self.run_command ('build_ext')
# Install everything: simply dump the entire contents of the build # Install everything: simply dump the entire contents of the build
# directory to the installation directory (that's the beauty of # directory to the installation directory (that's the beauty of
@ -85,7 +85,7 @@ def _mutate_outputs (self, has_any, build_cmd, cmd_option, output_dir):
if not has_any: if not has_any:
return [] return []
build_cmd = self.find_peer (build_cmd) build_cmd = self.get_finalized_command (build_cmd)
build_files = build_cmd.get_outputs() build_files = build_cmd.get_outputs()
build_dir = getattr (build_cmd, cmd_option) build_dir = getattr (build_cmd, cmd_option)
@ -138,11 +138,11 @@ def get_inputs (self):
inputs = [] inputs = []
if self.distribution.has_pure_modules(): if self.distribution.has_pure_modules():
build_py = self.find_peer ('build_py') build_py = self.get_finalized_command ('build_py')
inputs.extend (build_py.get_outputs()) inputs.extend (build_py.get_outputs())
if self.distribution.has_ext_modules(): if self.distribution.has_ext_modules():
build_ext = self.find_peer ('build_ext') build_ext = self.get_finalized_command ('build_ext')
inputs.extend (build_ext.get_outputs()) inputs.extend (build_ext.get_outputs())
return inputs return inputs

View file

@ -35,7 +35,7 @@ def finalize_options (self):
def run (self): def run (self):
if not self.skip_build: if not self.skip_build:
self.run_peer('build_scripts') self.run_command('build_scripts')
self.outfiles = self.copy_tree (self.build_dir, self.install_dir) self.outfiles = self.copy_tree (self.build_dir, self.install_dir)
if os.name == 'posix': if os.name == 'posix':
# Set the executable bits (owner, group, and world) on # Set the executable bits (owner, group, and world) on

View file

@ -223,15 +223,15 @@ def find_defaults (self):
self.files.extend (files) self.files.extend (files)
if self.distribution.has_pure_modules(): if self.distribution.has_pure_modules():
build_py = self.find_peer ('build_py') build_py = self.get_finalized_command ('build_py')
self.files.extend (build_py.get_source_files ()) self.files.extend (build_py.get_source_files ())
if self.distribution.has_ext_modules(): if self.distribution.has_ext_modules():
build_ext = self.find_peer ('build_ext') build_ext = self.get_finalized_command ('build_ext')
self.files.extend (build_ext.get_source_files ()) self.files.extend (build_ext.get_source_files ())
if self.distribution.has_c_libraries(): if self.distribution.has_c_libraries():
build_clib = self.find_peer ('build_clib') build_clib = self.get_finalized_command ('build_clib')
self.files.extend (build_clib.get_source_files ()) self.files.extend (build_clib.get_source_files ())
@ -441,7 +441,7 @@ def read_template (self):
# while loop over lines of template file # while loop over lines of template file
# Prune away the build and source distribution directories # Prune away the build and source distribution directories
build = self.find_peer ('build') build = self.get_finalized_command ('build')
exclude_pattern (self.files, None, prefix=build.build_base) exclude_pattern (self.files, None, prefix=build.build_base)
base_dir = self.distribution.get_fullname() base_dir = self.distribution.get_fullname()

View file

@ -681,7 +681,7 @@ def run_command (self, command):
self.announce ("running " + command) self.announce ("running " + command)
cmd_obj = self.get_command_obj (command) cmd_obj = self.get_command_obj (command)
cmd_obj.ensure_ready () cmd_obj.ensure_finalized ()
cmd_obj.run () cmd_obj.run ()
self.have_run[command] = 1 self.have_run[command] = 1