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 @@ class Command:
# none of that complicated bureaucracy is needed.
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
# this flag: it is the business of 'ensure_ready()', which always
# calls 'finalize_options()', to respect/update it.
self.ready = 0
# this flag: it is the business of 'ensure_finalized()', which
# always calls 'finalize_options()', to respect/update it.
self.finalized = 0
# __init__ ()
@ -89,10 +89,10 @@ class Command:
raise AttributeError, attr
def ensure_ready (self):
if not self.ready:
def ensure_finalized (self):
if not self.finalized:
self.finalize_options ()
self.ready = 1
self.finalized = 1
# Subclasses must define:
@ -184,32 +184,24 @@ class Command:
# Option_pairs: list of (src_option, dst_option) tuples
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:
if getattr (self, dst_option) is None:
setattr (self, dst_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:
find (create if necessary and 'create' is true) the command
object for 'command'.."""
cmd_obj = self.distribution.get_command_obj (command, create)
cmd_obj.ensure_ready ()
cmd_obj.ensure_finalized ()
return cmd_obj
def get_peer_option (self, command, option):
"""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):
def run_command (self, command):
"""Run some other command: uses the 'run_command()' method of
Distribution, which creates the command object if necessary
and then invokes its 'run()' method."""

View File

@ -53,7 +53,7 @@ class bdist (Command):
# temporary directories (eg. we'll probably have
# "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
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()
self.bdist_base = os.path.join (build_base, 'bdist.' + plat)
@ -79,9 +79,9 @@ class bdist (Command):
"invalid archive format '%s'" % self.format
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
self.run_peer (cmd_name)
self.run_command (cmd_name)
# run()

View File

@ -40,7 +40,7 @@ class bdist_dumb (Command):
def finalize_options (self):
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')
if self.format is None:
@ -56,10 +56,10 @@ class bdist_dumb (Command):
def run (self):
self.run_peer ('build')
self.run_command ('build')
# XXX don't use 'self.find_peer()', because it always runs
# 'ensure_ready()' on the command object; we explictly want a
# XXX don't use 'self.get_finalized_command()', because it always runs
# 'ensure_finalized()' on the command object; we explictly want a
# 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
# a proper "fake install" using this install command object.)
@ -67,7 +67,7 @@ class bdist_dumb (Command):
install.root = self.bdist_dir
self.announce ("installing to %s" % self.bdist_dir)
install.ensure_ready()
install.ensure_finalized()
install.run()
# And make an archive relative to the root of the

View File

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

View File

@ -92,20 +92,20 @@ class build (Command):
# Invoke the 'build_py' command to "build" pure Python modules
# (ie. copy 'em into the build tree)
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
# be needed by extension modules, so obviously have to be done
# first!
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
# into the build tree
if self.distribution.has_ext_modules():
self.run_peer ('build_ext')
self.run_command ('build_ext')
if self.distribution.has_scripts():
self.run_peer ('build_scripts')
self.run_command ('build_scripts')
# class build

View File

@ -167,7 +167,7 @@ class build_ext (Command):
# directory where we put them is in the library search path for
# linking extensions.
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.library_dirs.append (build_clib.build_clib)
@ -294,7 +294,7 @@ class build_ext (Command):
package = string.join (modpath[0:-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)
ext_filename = os.path.join (package_dir,
self.get_ext_filename(base))

View File

@ -454,11 +454,11 @@ class install (Command):
# Obviously have to build before we can install
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)
for cmd_name in self.get_sub_commands():
self.run_peer (cmd_name)
self.run_command (cmd_name)
if self.path_file:
self.create_path_file ()
@ -507,7 +507,7 @@ class install (Command):
# get the outputs of all its sub-commands.
outputs = []
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())
return outputs
@ -517,7 +517,7 @@ class install (Command):
# XXX gee, this looks familiar ;-(
inputs = []
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())
return inputs

View File

@ -46,9 +46,9 @@ class install_lib (Command):
# Make sure we have built everything we need first
if not self.skip_build:
if self.distribution.has_pure_modules():
self.run_peer ('build_py')
self.run_command ('build_py')
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
# directory to the installation directory (that's the beauty of
@ -85,7 +85,7 @@ class install_lib (Command):
if not has_any:
return []
build_cmd = self.find_peer (build_cmd)
build_cmd = self.get_finalized_command (build_cmd)
build_files = build_cmd.get_outputs()
build_dir = getattr (build_cmd, cmd_option)
@ -138,11 +138,11 @@ class install_lib (Command):
inputs = []
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())
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())
return inputs

View File

@ -35,7 +35,7 @@ class install_scripts (Command):
def run (self):
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)
if os.name == 'posix':
# Set the executable bits (owner, group, and world) on

View File

@ -223,15 +223,15 @@ class sdist (Command):
self.files.extend (files)
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 ())
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 ())
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 ())
@ -441,7 +441,7 @@ class sdist (Command):
# while loop over lines of template file
# 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)
base_dir = self.distribution.get_fullname()

View File

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