Commit fcaddaa4 authored by Jeremy Hylton's avatar Jeremy Hylton

Make setup.py less chatty by default.

This is a conservative version of SF patch 504889.  It uses the log
module instead of calling print in various places, and it ignores the
verbose argument passed to many functions and set as an attribute on
some objects.  Instead, it uses the verbosity set on the logger via
the command line.

The log module is now preferred over announce() and warn() methods
that exist only for backwards compatibility.

XXX This checkin changes a lot of modules that have no test suite and
aren't exercised by the Python build process.  It will need
substantial testing.
parent 6b2531b4
...@@ -11,6 +11,7 @@ import os ...@@ -11,6 +11,7 @@ import os
from distutils.errors import DistutilsExecError from distutils.errors import DistutilsExecError
from distutils.spawn import spawn from distutils.spawn import spawn
from distutils.dir_util import mkpath from distutils.dir_util import mkpath
from distutils import log
def make_tarball (base_name, base_dir, compress="gzip", def make_tarball (base_name, base_dir, compress="gzip",
verbose=0, dry_run=0): verbose=0, dry_run=0):
...@@ -42,13 +43,13 @@ def make_tarball (base_name, base_dir, compress="gzip", ...@@ -42,13 +43,13 @@ def make_tarball (base_name, base_dir, compress="gzip",
"bad value for 'compress': must be None, 'gzip', or 'compress'" "bad value for 'compress': must be None, 'gzip', or 'compress'"
archive_name = base_name + ".tar" archive_name = base_name + ".tar"
mkpath(os.path.dirname(archive_name), verbose=verbose, dry_run=dry_run) mkpath(os.path.dirname(archive_name), dry_run=dry_run)
cmd = ["tar", "-cf", archive_name, base_dir] cmd = ["tar", "-cf", archive_name, base_dir]
spawn(cmd, verbose=verbose, dry_run=dry_run) spawn(cmd, dry_run=dry_run)
if compress: if compress:
spawn([compress] + compress_flags[compress] + [archive_name], spawn([compress] + compress_flags[compress] + [archive_name],
verbose=verbose, dry_run=dry_run) dry_run=dry_run)
return archive_name + compress_ext[compress] return archive_name + compress_ext[compress]
else: else:
return archive_name return archive_name
...@@ -69,10 +70,10 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0): ...@@ -69,10 +70,10 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0):
# no changes needed! # no changes needed!
zip_filename = base_name + ".zip" zip_filename = base_name + ".zip"
mkpath(os.path.dirname(zip_filename), verbose=verbose, dry_run=dry_run) mkpath(os.path.dirname(zip_filename), dry_run=dry_run)
try: try:
spawn(["zip", "-rq", zip_filename, base_dir], spawn(["zip", "-rq", zip_filename, base_dir],
verbose=verbose, dry_run=dry_run) dry_run=dry_run)
except DistutilsExecError: except DistutilsExecError:
# XXX really should distinguish between "couldn't find # XXX really should distinguish between "couldn't find
...@@ -89,10 +90,10 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0): ...@@ -89,10 +90,10 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0):
"could neither find a standalone zip utility nor " + "could neither find a standalone zip utility nor " +
"import the 'zipfile' module") % zip_filename "import the 'zipfile' module") % zip_filename
if verbose:
print "creating '%s' and adding '%s' to it" % \ log.info("creating '%s' and adding '%s' to it",
(zip_filename, base_dir) zip_filename, base_dir)
def visit (z, dirname, names): def visit (z, dirname, names):
for name in names: for name in names:
path = os.path.normpath(os.path.join(dirname, name)) path = os.path.normpath(os.path.join(dirname, name))
...@@ -141,8 +142,7 @@ def make_archive (base_name, format, ...@@ -141,8 +142,7 @@ def make_archive (base_name, format,
""" """
save_cwd = os.getcwd() save_cwd = os.getcwd()
if root_dir is not None: if root_dir is not None:
if verbose: log.debug("changing into '%s'", root_dir)
print "changing into '%s'" % root_dir
base_name = os.path.abspath(base_name) base_name = os.path.abspath(base_name)
if not dry_run: if not dry_run:
os.chdir(root_dir) os.chdir(root_dir)
...@@ -150,8 +150,7 @@ def make_archive (base_name, format, ...@@ -150,8 +150,7 @@ def make_archive (base_name, format,
if base_dir is None: if base_dir is None:
base_dir = os.curdir base_dir = os.curdir
kwargs = { 'verbose': verbose, kwargs = { 'dry_run': dry_run }
'dry_run': dry_run }
try: try:
format_info = ARCHIVE_FORMATS[format] format_info = ARCHIVE_FORMATS[format]
...@@ -164,8 +163,7 @@ def make_archive (base_name, format, ...@@ -164,8 +163,7 @@ def make_archive (base_name, format,
filename = apply(func, (base_name, base_dir), kwargs) filename = apply(func, (base_name, base_dir), kwargs)
if root_dir is not None: if root_dir is not None:
if verbose: log.debug("changing back to '%s'", save_cwd)
print "changing back to '%s'" % save_cwd
os.chdir(save_cwd) os.chdir(save_cwd)
return filename return filename
......
...@@ -22,6 +22,7 @@ from distutils.ccompiler import \ ...@@ -22,6 +22,7 @@ from distutils.ccompiler import \
CCompiler, gen_preprocess_options, gen_lib_options CCompiler, gen_preprocess_options, gen_lib_options
from distutils.file_util import write_file from distutils.file_util import write_file
from distutils.dep_util import newer from distutils.dep_util import newer
from distutils import log
class BCPPCompiler(CCompiler) : class BCPPCompiler(CCompiler) :
"""Concrete class that implements an interface to the Borland C/C++ """Concrete class that implements an interface to the Borland C/C++
...@@ -108,7 +109,7 @@ class BCPPCompiler(CCompiler) : ...@@ -108,7 +109,7 @@ class BCPPCompiler(CCompiler) :
ext = (os.path.splitext (src))[1] ext = (os.path.splitext (src))[1]
if skip_sources[src]: if skip_sources[src]:
self.announce ("skipping %s (%s up-to-date)" % (src, obj)) log.debug("skipping %s (%s up-to-date)", src, obj)
else: else:
src = os.path.normpath(src) src = os.path.normpath(src)
obj = os.path.normpath(obj) obj = os.path.normpath(obj)
...@@ -178,7 +179,7 @@ class BCPPCompiler(CCompiler) : ...@@ -178,7 +179,7 @@ class BCPPCompiler(CCompiler) :
except DistutilsExecError, msg: except DistutilsExecError, msg:
raise LibError, msg raise LibError, msg
else: else:
self.announce ("skipping %s (up-to-date)" % output_filename) log.debug("skipping %s (up-to-date)", output_filename)
# create_static_lib () # create_static_lib ()
...@@ -205,8 +206,8 @@ class BCPPCompiler(CCompiler) : ...@@ -205,8 +206,8 @@ class BCPPCompiler(CCompiler) :
self._fix_lib_args (libraries, library_dirs, runtime_library_dirs) self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
if runtime_library_dirs: if runtime_library_dirs:
self.warn ("I don't know what to do with 'runtime_library_dirs': " log.warn("I don't know what to do with 'runtime_library_dirs': %s",
+ str (runtime_library_dirs)) str(runtime_library_dirs))
if output_dir is not None: if output_dir is not None:
output_filename = os.path.join (output_dir, output_filename) output_filename = os.path.join (output_dir, output_filename)
...@@ -285,7 +286,6 @@ class BCPPCompiler(CCompiler) : ...@@ -285,7 +286,6 @@ class BCPPCompiler(CCompiler) :
if libfile is None: if libfile is None:
ld_args.append(lib) ld_args.append(lib)
# probably a BCPP internal library -- don't warn # probably a BCPP internal library -- don't warn
# self.warn('library %s not found.' % lib)
else: else:
# full name which prefers bcpp_xxx.lib over xxx.lib # full name which prefers bcpp_xxx.lib over xxx.lib
ld_args.append(libfile) ld_args.append(libfile)
...@@ -313,7 +313,7 @@ class BCPPCompiler(CCompiler) : ...@@ -313,7 +313,7 @@ class BCPPCompiler(CCompiler) :
raise LinkError, msg raise LinkError, msg
else: else:
self.announce ("skipping %s (up-to-date)" % output_filename) log.debug("skipping %s (up-to-date)", output_filename)
# link () # link ()
......
...@@ -16,7 +16,7 @@ from distutils.file_util import move_file ...@@ -16,7 +16,7 @@ from distutils.file_util import move_file
from distutils.dir_util import mkpath from distutils.dir_util import mkpath
from distutils.dep_util import newer_pairwise, newer_group from distutils.dep_util import newer_pairwise, newer_group
from distutils.util import split_quoted, execute from distutils.util import split_quoted, execute
from distutils import log
class CCompiler: class CCompiler:
"""Abstract base class to define the interface that must be implemented """Abstract base class to define the interface that must be implemented
...@@ -80,7 +80,6 @@ class CCompiler: ...@@ -80,7 +80,6 @@ class CCompiler:
dry_run=0, dry_run=0,
force=0): force=0):
self.verbose = verbose
self.dry_run = dry_run self.dry_run = dry_run
self.force = force self.force = force
...@@ -808,8 +807,7 @@ class CCompiler: ...@@ -808,8 +807,7 @@ class CCompiler:
# -- Utility methods ----------------------------------------------- # -- Utility methods -----------------------------------------------
def announce (self, msg, level=1): def announce (self, msg, level=1):
if self.verbose >= level: log.debug(msg)
print msg
def debug_print (self, msg): def debug_print (self, msg):
from distutils.core import DEBUG from distutils.core import DEBUG
...@@ -820,16 +818,16 @@ class CCompiler: ...@@ -820,16 +818,16 @@ class CCompiler:
sys.stderr.write ("warning: %s\n" % msg) sys.stderr.write ("warning: %s\n" % msg)
def execute (self, func, args, msg=None, level=1): def execute (self, func, args, msg=None, level=1):
execute(func, args, msg, self.verbose >= level, self.dry_run) execute(func, args, msg, self.dry_run)
def spawn (self, cmd): def spawn (self, cmd):
spawn (cmd, verbose=self.verbose, dry_run=self.dry_run) spawn (cmd, dry_run=self.dry_run)
def move_file (self, src, dst): def move_file (self, src, dst):
return move_file (src, dst, verbose=self.verbose, dry_run=self.dry_run) return move_file (src, dst, dry_run=self.dry_run)
def mkpath (self, name, mode=0777): def mkpath (self, name, mode=0777):
mkpath (name, mode, self.verbose, self.dry_run) mkpath (name, mode, self.dry_run)
# class CCompiler # class CCompiler
...@@ -957,7 +955,10 @@ def new_compiler (plat=None, ...@@ -957,7 +955,10 @@ def new_compiler (plat=None,
("can't compile C/C++ code: unable to find class '%s' " + ("can't compile C/C++ code: unable to find class '%s' " +
"in module '%s'") % (class_name, module_name) "in module '%s'") % (class_name, module_name)
return klass (verbose, dry_run, force) # XXX The None is necessary to preserve backwards compatibility
# with classes that expect verbose to be the first positional
# argument.
return klass (None, dry_run, force)
def gen_preprocess_options (macros, include_dirs): def gen_preprocess_options (macros, include_dirs):
......
...@@ -13,7 +13,7 @@ import sys, os, string, re ...@@ -13,7 +13,7 @@ import sys, os, string, re
from types import * from types import *
from distutils.errors import * from distutils.errors import *
from distutils import util, dir_util, file_util, archive_util, dep_util from distutils import util, dir_util, file_util, archive_util, dep_util
from distutils import log
class Command: class Command:
"""Abstract base class for defining command classes, the "worker bees" """Abstract base class for defining command classes, the "worker bees"
...@@ -72,11 +72,15 @@ class Command: ...@@ -72,11 +72,15 @@ class Command:
# commands fallback on the Distribution's behaviour. None means # commands fallback on the Distribution's behaviour. None means
# "not defined, check self.distribution's copy", while 0 or 1 mean # "not defined, check self.distribution's copy", while 0 or 1 mean
# false and true (duh). Note that this means figuring out the real # false and true (duh). Note that this means figuring out the real
# value of each flag is a touch complicated -- hence "self.verbose" # value of each flag is a touch complicated -- hence "self._dry_run"
# (etc.) will be handled by __getattr__, below. # will be handled by __getattr__, below.
self._verbose = None # XXX This needs to be fixed.
self._dry_run = None self._dry_run = None
# verbose is largely ignored, but needs to be set for
# backwards compatibility (I think)?
self.verbose = dist.verbose
# Some commands define a 'self.force' option to ignore file # Some commands define a 'self.force' option to ignore file
# timestamps, but methods defined *here* assume that # timestamps, but methods defined *here* assume that
# 'self.force' exists for all commands. So define it here # 'self.force' exists for all commands. So define it here
...@@ -96,8 +100,10 @@ class Command: ...@@ -96,8 +100,10 @@ class Command:
# __init__ () # __init__ ()
# XXX A more explicit way to customize dry_run would be better.
def __getattr__ (self, attr): def __getattr__ (self, attr):
if attr in ('verbose', 'dry_run'): if attr == 'dry_run':
myval = getattr(self, "_" + attr) myval = getattr(self, "_" + attr)
if myval is None: if myval is None:
return getattr(self.distribution, attr) return getattr(self.distribution, attr)
...@@ -186,9 +192,7 @@ class Command: ...@@ -186,9 +192,7 @@ class Command:
"""If the current verbosity level is of greater than or equal to """If the current verbosity level is of greater than or equal to
'level' print 'msg' to stdout. 'level' print 'msg' to stdout.
""" """
if self.verbose >= level: log.debug(msg)
print msg
sys.stdout.flush()
def debug_print (self, msg): def debug_print (self, msg):
"""Print 'msg' to stdout if the global DEBUG (taken from the """Print 'msg' to stdout if the global DEBUG (taken from the
...@@ -352,12 +356,11 @@ class Command: ...@@ -352,12 +356,11 @@ class Command:
def execute (self, func, args, msg=None, level=1): def execute (self, func, args, msg=None, level=1):
util.execute(func, args, msg, self.verbose >= level, self.dry_run) util.execute(func, args, msg, dry_run=self.dry_run)
def mkpath (self, name, mode=0777): def mkpath (self, name, mode=0777):
dir_util.mkpath(name, mode, dir_util.mkpath(name, mode, dry_run=self.dry_run)
self.verbose, self.dry_run)
def copy_file (self, infile, outfile, def copy_file (self, infile, outfile,
...@@ -371,8 +374,7 @@ class Command: ...@@ -371,8 +374,7 @@ class Command:
preserve_mode, preserve_times, preserve_mode, preserve_times,
not self.force, not self.force,
link, link,
self.verbose >= level, dry_run=self.dry_run)
self.dry_run)
def copy_tree (self, infile, outfile, def copy_tree (self, infile, outfile,
...@@ -385,30 +387,21 @@ class Command: ...@@ -385,30 +387,21 @@ class Command:
infile, outfile, infile, outfile,
preserve_mode,preserve_times,preserve_symlinks, preserve_mode,preserve_times,preserve_symlinks,
not self.force, not self.force,
self.verbose >= level, dry_run=self.dry_run)
self.dry_run)
def move_file (self, src, dst, level=1): def move_file (self, src, dst, level=1):
"""Move a file respecting verbose and dry-run flags.""" """Move a file respectin dry-run flag."""
return file_util.move_file(src, dst, return file_util.move_file(src, dst, dry_run = self.dry_run)
self.verbose >= level,
self.dry_run)
def spawn (self, cmd, search_path=1, level=1): def spawn (self, cmd, search_path=1, level=1):
"""Spawn an external command respecting verbose and dry-run flags.""" """Spawn an external command respecting dry-run flag."""
from distutils.spawn import spawn from distutils.spawn import spawn
spawn(cmd, search_path, spawn(cmd, search_path, dry_run= self.dry_run)
self.verbose >= level,
self.dry_run)
def make_archive (self, base_name, format, def make_archive (self, base_name, format,
root_dir=None, base_dir=None): root_dir=None, base_dir=None):
return archive_util.make_archive( return archive_util.make_archive(
base_name, format, root_dir, base_dir, base_name, format, root_dir, base_dir, dry_run=self.dry_run)
self.verbose, self.dry_run)
def make_file (self, infiles, outfile, func, args, def make_file (self, infiles, outfile, func, args,
...@@ -443,7 +436,7 @@ class Command: ...@@ -443,7 +436,7 @@ class Command:
# Otherwise, print the "skip" message # Otherwise, print the "skip" message
else: else:
self.announce(skip_msg, level) log.debug(skip_msg)
# make_file () # make_file ()
......
...@@ -13,6 +13,7 @@ from distutils.core import Command ...@@ -13,6 +13,7 @@ from distutils.core import Command
from distutils.util import get_platform from distutils.util import get_platform
from distutils.dir_util import create_tree, remove_tree from distutils.dir_util import create_tree, remove_tree
from distutils.errors import * from distutils.errors import *
from distutils import log
class bdist_dumb (Command): class bdist_dumb (Command):
...@@ -83,7 +84,7 @@ class bdist_dumb (Command): ...@@ -83,7 +84,7 @@ class bdist_dumb (Command):
install.skip_build = self.skip_build install.skip_build = self.skip_build
install.warn_dir = 0 install.warn_dir = 0
self.announce("installing to %s" % self.bdist_dir) log.info("installing to %s" % self.bdist_dir)
self.run_command('install') self.run_command('install')
# And make an archive relative to the root of the # And make an archive relative to the root of the
...@@ -101,7 +102,7 @@ class bdist_dumb (Command): ...@@ -101,7 +102,7 @@ class bdist_dumb (Command):
root_dir=self.bdist_dir) root_dir=self.bdist_dir)
if not self.keep_temp: if not self.keep_temp:
remove_tree(self.bdist_dir, self.verbose, self.dry_run) remove_tree(self.bdist_dir, dry_run=self.dry_run)
# run() # run()
......
...@@ -14,6 +14,7 @@ from distutils.util import get_platform ...@@ -14,6 +14,7 @@ from distutils.util import get_platform
from distutils.dir_util import create_tree, remove_tree from distutils.dir_util import create_tree, remove_tree
from distutils.file_util import write_file from distutils.file_util import write_file
from distutils.errors import * from distutils.errors import *
from distutils import log
import string, sys import string, sys
class bdist_packager (Command): class bdist_packager (Command):
...@@ -102,8 +103,8 @@ class bdist_packager (Command): ...@@ -102,8 +103,8 @@ class bdist_packager (Command):
else: else:
setattr(self,attr,default) setattr(self,attr,default)
val = default val = default
if val!="": if val != "":
self.announce('Creating %s script', attr) log.info('Creating %s script', attr)
self.execute(write_file, self.execute(write_file,
(path, self.get_script(attr)), (path, self.get_script(attr)),
"writing '%s'" % path) "writing '%s'" % path)
...@@ -234,7 +235,7 @@ class bdist_packager (Command): ...@@ -234,7 +235,7 @@ class bdist_packager (Command):
install = self.reinitialize_command('install', reinit_subcommands=1) install = self.reinitialize_command('install', reinit_subcommands=1)
install.root = self.pkg_dir install.root = self.pkg_dir
self.announce("installing to %s" % self.pkg_dir) log.info("installing to %s", self.pkg_dir)
self.run_command('install') self.run_command('install')
# And make an archive relative to the root of the # And make an archive relative to the root of the
...@@ -243,7 +244,7 @@ class bdist_packager (Command): ...@@ -243,7 +244,7 @@ class bdist_packager (Command):
self.plat_name) self.plat_name)
if not self.keep_temp: if not self.keep_temp:
remove_tree(self.pkg_dir, self.verbose, self.dry_run) remove_tree(self.pkg_dir, dry_run=self.dry_run)
# run() # run()
......
...@@ -15,6 +15,7 @@ from distutils.file_util import write_file ...@@ -15,6 +15,7 @@ from distutils.file_util import write_file
from distutils.errors import * from distutils.errors import *
from distutils.command import bdist_packager from distutils.command import bdist_packager
from distutils import sysconfig from distutils import sysconfig
from distutils import log
import compileall import compileall
from commands import getoutput from commands import getoutput
...@@ -211,9 +212,9 @@ class bdist_pkgtool (bdist_packager.bdist_packager): ...@@ -211,9 +212,9 @@ class bdist_pkgtool (bdist_packager.bdist_packager):
install = self.reinitialize_command('install', reinit_subcommands=1) install = self.reinitialize_command('install', reinit_subcommands=1)
# build package # build package
self.announce('Building package') log.info('Building package')
self.run_command('build') self.run_command('build')
self.announce('Creating pkginfo file') log.info('Creating pkginfo file')
path = os.path.join(pkg_dir, "pkginfo") path = os.path.join(pkg_dir, "pkginfo")
self.execute(write_file, self.execute(write_file,
(path, (path,
...@@ -244,7 +245,7 @@ class bdist_pkgtool (bdist_packager.bdist_packager): ...@@ -244,7 +245,7 @@ class bdist_pkgtool (bdist_packager.bdist_packager):
self.write_script(os.path.join(pkg_dir, "depend"), self.write_script(os.path.join(pkg_dir, "depend"),
'depend',None) 'depend',None)
self.announce('Creating prototype file') log.info('Creating prototype file')
path = os.path.join(pkg_dir, "prototype") path = os.path.join(pkg_dir, "prototype")
self.execute(write_file, self.execute(write_file,
(path, (path,
...@@ -256,7 +257,7 @@ class bdist_pkgtool (bdist_packager.bdist_packager): ...@@ -256,7 +257,7 @@ class bdist_pkgtool (bdist_packager.bdist_packager):
return return
self.announce('Creating package') log.info('Creating package')
pkg_cmd = ['pkgmk', '-o', '-f'] pkg_cmd = ['pkgmk', '-o', '-f']
pkg_cmd.append(path) pkg_cmd.append(path)
pkg_cmd.append('-b') pkg_cmd.append('-b')
...@@ -265,7 +266,7 @@ class bdist_pkgtool (bdist_packager.bdist_packager): ...@@ -265,7 +266,7 @@ class bdist_pkgtool (bdist_packager.bdist_packager):
pkg_cmd = ['pkgtrans', '-s', '/var/spool/pkg'] pkg_cmd = ['pkgtrans', '-s', '/var/spool/pkg']
path = os.path.join(os.environ['PWD'],pkg_dir, path = os.path.join(os.environ['PWD'],pkg_dir,
self.get_binary_name() + ".pkg") self.get_binary_name() + ".pkg")
self.announce('Transferring package to ' + pkg_dir) log.info('Transferring package to ' + pkg_dir)
pkg_cmd.append(path) pkg_cmd.append(path)
pkg_cmd.append(self.pkg_abrev) pkg_cmd.append(self.pkg_abrev)
self.spawn(pkg_cmd) self.spawn(pkg_cmd)
...@@ -326,7 +327,7 @@ class bdist_pkgtool (bdist_packager.bdist_packager): ...@@ -326,7 +327,7 @@ class bdist_pkgtool (bdist_packager.bdist_packager):
if self.no_autorelocate==0: if self.no_autorelocate==0:
request=string.split(DEFAULT_REQUEST,"\012") request=string.split(DEFAULT_REQUEST,"\012")
else: else:
self.announce('Creating relocation request script') log.info('Creating relocation request script')
if self.request: if self.request:
users_request=self.get_script('request') users_request=self.get_script('request')
if users_request!=None and users_request!=[]: if users_request!=None and users_request!=[]:
......
...@@ -14,6 +14,7 @@ from distutils.core import Command, DEBUG ...@@ -14,6 +14,7 @@ from distutils.core import Command, DEBUG
from distutils.util import get_platform from distutils.util import get_platform
from distutils.file_util import write_file from distutils.file_util import write_file
from distutils.errors import * from distutils.errors import *
from distutils import log
class bdist_rpm (Command): class bdist_rpm (Command):
...@@ -278,7 +279,7 @@ class bdist_rpm (Command): ...@@ -278,7 +279,7 @@ class bdist_rpm (Command):
# build package # build package
self.announce('building RPMs') log.info("building RPMs")
rpm_cmd = ['rpm'] rpm_cmd = ['rpm']
if self.source_only: # what kind of RPMs? if self.source_only: # what kind of RPMs?
rpm_cmd.append('-bs') rpm_cmd.append('-bs')
......
...@@ -14,6 +14,7 @@ from distutils.util import get_platform ...@@ -14,6 +14,7 @@ from distutils.util import get_platform
from distutils.file_util import write_file from distutils.file_util import write_file
from distutils.errors import * from distutils.errors import *
from distutils.command import bdist_packager from distutils.command import bdist_packager
from distutils import log
import sys import sys
from commands import getoutput from commands import getoutput
...@@ -185,9 +186,9 @@ class bdist_sdux(bdist_packager.bdist_packager): ...@@ -185,9 +186,9 @@ class bdist_sdux(bdist_packager.bdist_packager):
psf_path = os.path.join(self.pkg_dir, psf_path = os.path.join(self.pkg_dir,
"%s.psf" % self.get_binary_name()) "%s.psf" % self.get_binary_name())
# build package # build package
self.announce('Building package') log.info('Building package')
self.run_command('build') self.run_command('build')
self.announce('Creating psf file') log.info('Creating psf file')
self.execute(write_file, self.execute(write_file,
(psf_path, (psf_path,
self._make_control_file()), self._make_control_file()),
...@@ -195,7 +196,7 @@ class bdist_sdux(bdist_packager.bdist_packager): ...@@ -195,7 +196,7 @@ class bdist_sdux(bdist_packager.bdist_packager):
if self.control_only: # stop if requested if self.control_only: # stop if requested
return return
self.announce('Creating package') log.info('Creating package')
spawn_cmd = ['swpackage', '-s'] spawn_cmd = ['swpackage', '-s']
spawn_cmd.append(psf_path) spawn_cmd.append(psf_path)
spawn_cmd.append('-x') spawn_cmd.append('-x')
......
...@@ -12,6 +12,7 @@ from distutils.core import Command ...@@ -12,6 +12,7 @@ from distutils.core import Command
from distutils.util import get_platform from distutils.util import get_platform
from distutils.dir_util import create_tree, remove_tree from distutils.dir_util import create_tree, remove_tree
from distutils.errors import * from distutils.errors import *
from distutils import log
class bdist_wininst (Command): class bdist_wininst (Command):
...@@ -115,7 +116,7 @@ class bdist_wininst (Command): ...@@ -115,7 +116,7 @@ class bdist_wininst (Command):
'install_' + key, 'install_' + key,
value) value)
self.announce("installing to %s" % self.bdist_dir) log.info("installing to %s", self.bdist_dir)
install.ensure_finalized() install.ensure_finalized()
# avoid warning of 'install_lib' about installing # avoid warning of 'install_lib' about installing
...@@ -136,11 +137,11 @@ class bdist_wininst (Command): ...@@ -136,11 +137,11 @@ class bdist_wininst (Command):
# create an exe containing the zip-file # create an exe containing the zip-file
self.create_exe(arcname, fullname, self.bitmap) self.create_exe(arcname, fullname, self.bitmap)
# remove the zip-file again # remove the zip-file again
self.announce("removing temporary file '%s'" % arcname) log.debug("removing temporary file '%s'", arcname)
os.remove(arcname) os.remove(arcname)
if not self.keep_temp: if not self.keep_temp:
remove_tree(self.bdist_dir, self.verbose, self.dry_run) remove_tree(self.bdist_dir, dry_run=self.dry_run)
# run() # run()
......
...@@ -24,7 +24,7 @@ from types import * ...@@ -24,7 +24,7 @@ from types import *
from distutils.core import Command from distutils.core import Command
from distutils.errors import * from distutils.errors import *
from distutils.sysconfig import customize_compiler from distutils.sysconfig import customize_compiler
from distutils import log
def show_compilers (): def show_compilers ():
from distutils.ccompiler import show_compilers from distutils.ccompiler import show_compilers
...@@ -111,7 +111,6 @@ class build_clib (Command): ...@@ -111,7 +111,6 @@ class build_clib (Command):
# Yech -- this is cut 'n pasted from build_ext.py! # Yech -- this is cut 'n pasted from build_ext.py!
from distutils.ccompiler import new_compiler from distutils.ccompiler import new_compiler
self.compiler = new_compiler(compiler=self.compiler, self.compiler = new_compiler(compiler=self.compiler,
verbose=self.verbose,
dry_run=self.dry_run, dry_run=self.dry_run,
force=self.force) force=self.force)
customize_compiler(self.compiler) customize_compiler(self.compiler)
...@@ -213,7 +212,7 @@ class build_clib (Command): ...@@ -213,7 +212,7 @@ class build_clib (Command):
"a list of source filenames") % lib_name "a list of source filenames") % lib_name
sources = list(sources) sources = list(sources)
self.announce("building '%s' library" % lib_name) log.info("building '%s' library", lib_name)
# First, compile the source code to object files in the library # First, compile the source code to object files in the library
# directory. (This should probably change to putting object # directory. (This should probably change to putting object
......
...@@ -15,6 +15,7 @@ from distutils.errors import * ...@@ -15,6 +15,7 @@ from distutils.errors import *
from distutils.sysconfig import customize_compiler from distutils.sysconfig import customize_compiler
from distutils.dep_util import newer_group from distutils.dep_util import newer_group
from distutils.extension import Extension from distutils.extension import Extension
from distutils import log
# An extension name is just a dot-separated list of Python NAMEs (ie. # An extension name is just a dot-separated list of Python NAMEs (ie.
# the same as a fully-qualified module name). # the same as a fully-qualified module name).
...@@ -291,9 +292,9 @@ class build_ext (Command): ...@@ -291,9 +292,9 @@ class build_ext (Command):
# by Extension constructor) # by Extension constructor)
(ext_name, build_info) = ext (ext_name, build_info) = ext
self.warn(("old-style (ext_name, build_info) tuple found in " log.warn(("old-style (ext_name, build_info) tuple found in "
"ext_modules for extension '%s'" "ext_modules for extension '%s'"
"-- please convert to Extension instance" % ext_name)) "-- please convert to Extension instance" % ext_name))
if type(ext) is not TupleType and len(ext) != 2: if type(ext) is not TupleType and len(ext) != 2:
raise DistutilsSetupError, \ raise DistutilsSetupError, \
("each element of 'ext_modules' option must be an " ("each element of 'ext_modules' option must be an "
...@@ -329,8 +330,8 @@ class build_ext (Command): ...@@ -329,8 +330,8 @@ class build_ext (Command):
# Medium-easy stuff: same syntax/semantics, different names. # Medium-easy stuff: same syntax/semantics, different names.
ext.runtime_library_dirs = build_info.get('rpath') ext.runtime_library_dirs = build_info.get('rpath')
if build_info.has_key('def_file'): if build_info.has_key('def_file'):
self.warn("'def_file' element of build info dict " log.warn("'def_file' element of build info dict "
"no longer supported") "no longer supported")
# Non-trivial stuff: 'macros' split into 'define_macros' # Non-trivial stuff: 'macros' split into 'define_macros'
# and 'undef_macros'. # and 'undef_macros'.
...@@ -422,11 +423,10 @@ class build_ext (Command): ...@@ -422,11 +423,10 @@ class build_ext (Command):
self.get_ext_filename(fullname)) self.get_ext_filename(fullname))
if not (self.force or newer_group(sources, ext_filename, 'newer')): if not (self.force or newer_group(sources, ext_filename, 'newer')):
self.announce("skipping '%s' extension (up-to-date)" % log.debug("skipping '%s' extension (up-to-date)", ext.name)
ext.name)
return return
else: else:
self.announce("building '%s' extension" % ext.name) log.info("building '%s' extension", ext.name)
# First, scan the sources for SWIG definition files (.i), run # First, scan the sources for SWIG definition files (.i), run
# SWIG on 'em to create .c files, and modify the sources list # SWIG on 'em to create .c files, and modify the sources list
...@@ -539,7 +539,7 @@ class build_ext (Command): ...@@ -539,7 +539,7 @@ class build_ext (Command):
for source in swig_sources: for source in swig_sources:
target = swig_targets[source] target = swig_targets[source]
self.announce("swigging %s to %s" % (source, target)) log.info("swigging %s to %s", source, target)
self.spawn(swig_cmd + ["-o", target, source]) self.spawn(swig_cmd + ["-o", target, source])
return new_sources return new_sources
......
...@@ -13,7 +13,7 @@ from glob import glob ...@@ -13,7 +13,7 @@ from glob import glob
from distutils.core import Command from distutils.core import Command
from distutils.errors import * from distutils.errors import *
from distutils.util import convert_path from distutils.util import convert_path
from distutils import log
class build_py (Command): class build_py (Command):
...@@ -176,8 +176,8 @@ class build_py (Command): ...@@ -176,8 +176,8 @@ class build_py (Command):
if os.path.isfile(init_py): if os.path.isfile(init_py):
return init_py return init_py
else: else:
self.warn(("package init file '%s' not found " + log.warn(("package init file '%s' not found " +
"(or not a regular file)") % init_py) "(or not a regular file)"), init_py)
# Either not in a package at all (__init__.py not expected), or # Either not in a package at all (__init__.py not expected), or
# __init__.py doesn't exist -- so don't return the filename. # __init__.py doesn't exist -- so don't return the filename.
...@@ -188,8 +188,7 @@ class build_py (Command): ...@@ -188,8 +188,7 @@ class build_py (Command):
def check_module (self, module, module_file): def check_module (self, module, module_file):
if not os.path.isfile(module_file): if not os.path.isfile(module_file):
self.warn("file %s (for module %s) not found" % log.warn("file %s (for module %s) not found", module_file, module)
(module_file, module))
return 0 return 0
else: else:
return 1 return 1
...@@ -389,13 +388,9 @@ class build_py (Command): ...@@ -389,13 +388,9 @@ class build_py (Command):
if self.compile: if self.compile:
byte_compile(files, optimize=0, byte_compile(files, optimize=0,
force=self.force, force=self.force, prefix=prefix, dry_run=self.dry_run)
prefix=prefix,
verbose=self.verbose, dry_run=self.dry_run)
if self.optimize > 0: if self.optimize > 0:
byte_compile(files, optimize=self.optimize, byte_compile(files, optimize=self.optimize,
force=self.force, force=self.force, prefix=prefix, dry_run=self.dry_run)
prefix=prefix,
verbose=self.verbose, dry_run=self.dry_run)
# class build_py # class build_py
...@@ -11,6 +11,7 @@ from distutils import sysconfig ...@@ -11,6 +11,7 @@ from distutils import sysconfig
from distutils.core import Command from distutils.core import Command
from distutils.dep_util import newer from distutils.dep_util import newer
from distutils.util import convert_path from distutils.util import convert_path
from distutils import log
# check if Python is called on the first line with this expression # check if Python is called on the first line with this expression
first_line_re = re.compile(r'^#!.*python[0-9.]*(\s+.*)?$') first_line_re = re.compile(r'^#!.*python[0-9.]*(\s+.*)?$')
...@@ -59,7 +60,7 @@ class build_scripts (Command): ...@@ -59,7 +60,7 @@ class build_scripts (Command):
outfile = os.path.join(self.build_dir, os.path.basename(script)) outfile = os.path.join(self.build_dir, os.path.basename(script))
if not self.force and not newer(script, outfile): if not self.force and not newer(script, outfile):
self.announce("not copying %s (up-to-date)" % script) log.debug("not copying %s (up-to-date)", script)
continue continue
# Always open the file, but ignore failures in dry-run mode -- # Always open the file, but ignore failures in dry-run mode --
...@@ -83,8 +84,8 @@ class build_scripts (Command): ...@@ -83,8 +84,8 @@ class build_scripts (Command):
post_interp = match.group(1) or '' post_interp = match.group(1) or ''
if adjust: if adjust:
self.announce("copying and adjusting %s -> %s" % log.info("copying and adjusting %s -> %s", script,
(script, self.build_dir)) self.build_dir)
if not self.dry_run: if not self.dry_run:
outf = open(outfile, "w") outf = open(outfile, "w")
if not sysconfig.python_build: if not sysconfig.python_build:
......
...@@ -9,6 +9,7 @@ __revision__ = "$Id$" ...@@ -9,6 +9,7 @@ __revision__ = "$Id$"
import os import os
from distutils.core import Command from distutils.core import Command
from distutils.dir_util import remove_tree from distutils.dir_util import remove_tree
from distutils import log
class clean (Command): class clean (Command):
...@@ -51,10 +52,10 @@ class clean (Command): ...@@ -51,10 +52,10 @@ class clean (Command):
# remove the build/temp.<plat> directory (unless it's already # remove the build/temp.<plat> directory (unless it's already
# gone) # gone)
if os.path.exists(self.build_temp): if os.path.exists(self.build_temp):
remove_tree(self.build_temp, self.verbose, self.dry_run) remove_tree(self.build_temp, dry_run=self.dry_run)
else: else:
self.warn("'%s' does not exist -- can't clean it" % log.warn("'%s' does not exist -- can't clean it",
self.build_temp) self.build_temp)
if self.all: if self.all:
# remove build directories # remove build directories
...@@ -62,17 +63,17 @@ class clean (Command): ...@@ -62,17 +63,17 @@ class clean (Command):
self.bdist_base, self.bdist_base,
self.build_scripts): self.build_scripts):
if os.path.exists(directory): if os.path.exists(directory):
remove_tree(directory, self.verbose, self.dry_run) remove_tree(directory, dry_run=self.dry_run)
else: else:
self.warn("'%s' does not exist -- can't clean it" % log.warn("'%s' does not exist -- can't clean it",
directory) directory)
# just for the heck of it, try to remove the base build directory: # just for the heck of it, try to remove the base build directory:
# we might have emptied it right now, but if not we don't care # we might have emptied it right now, but if not we don't care
if not self.dry_run: if not self.dry_run:
try: try:
os.rmdir(self.build_base) os.rmdir(self.build_base)
self.announce("removing '%s'" % self.build_base) log.info("removing '%s'", self.build_base)
except OSError: except OSError:
pass pass
......
...@@ -17,7 +17,7 @@ import sys, os, string, re ...@@ -17,7 +17,7 @@ import sys, os, string, re
from types import * from types import *
from distutils.core import Command from distutils.core import Command
from distutils.errors import DistutilsExecError from distutils.errors import DistutilsExecError
from distutils import log
LANG_EXT = {'c': '.c', LANG_EXT = {'c': '.c',
'c++': '.cxx'} 'c++': '.cxx'}
...@@ -103,9 +103,7 @@ class config (Command): ...@@ -103,9 +103,7 @@ class config (Command):
from distutils.ccompiler import CCompiler, new_compiler from distutils.ccompiler import CCompiler, new_compiler
if not isinstance(self.compiler, CCompiler): if not isinstance(self.compiler, CCompiler):
self.compiler = new_compiler(compiler=self.compiler, self.compiler = new_compiler(compiler=self.compiler,
verbose=self.noisy, dry_run=self.dry_run, force=1)
dry_run=self.dry_run,
force=1)
if self.include_dirs: if self.include_dirs:
self.compiler.set_include_dirs(self.include_dirs) self.compiler.set_include_dirs(self.include_dirs)
if self.libraries: if self.libraries:
...@@ -161,7 +159,7 @@ class config (Command): ...@@ -161,7 +159,7 @@ class config (Command):
if not filenames: if not filenames:
filenames = self.temp_files filenames = self.temp_files
self.temp_files = [] self.temp_files = []
self.announce("removing: " + string.join(filenames)) log.info("removing: %s", string.join(filenames))
for filename in filenames: for filename in filenames:
try: try:
os.remove(filename) os.remove(filename)
...@@ -239,7 +237,7 @@ class config (Command): ...@@ -239,7 +237,7 @@ class config (Command):
except CompileError: except CompileError:
ok = 0 ok = 0
self.announce(ok and "success!" or "failure.") log.info(ok and "success!" or "failure.")
self._clean() self._clean()
return ok return ok
...@@ -260,7 +258,7 @@ class config (Command): ...@@ -260,7 +258,7 @@ class config (Command):
except (CompileError, LinkError): except (CompileError, LinkError):
ok = 0 ok = 0
self.announce(ok and "success!" or "failure.") log.info(ok and "success!" or "failure.")
self._clean() self._clean()
return ok return ok
...@@ -282,7 +280,7 @@ class config (Command): ...@@ -282,7 +280,7 @@ class config (Command):
except (CompileError, LinkError, DistutilsExecError): except (CompileError, LinkError, DistutilsExecError):
ok = 0 ok = 0
self.announce(ok and "success!" or "failure.") log.info(ok and "success!" or "failure.")
self._clean() self._clean()
return ok return ok
......
...@@ -124,13 +124,11 @@ class install_lib (Command): ...@@ -124,13 +124,11 @@ class install_lib (Command):
if self.compile: if self.compile:
byte_compile(files, optimize=0, byte_compile(files, optimize=0,
force=self.force, force=self.force, prefix=install_root,
prefix=install_root, dry_run=self.dry_run)
verbose=self.verbose, dry_run=self.dry_run)
if self.optimize > 0: if self.optimize > 0:
byte_compile(files, optimize=self.optimize, byte_compile(files, optimize=self.optimize,
force=self.force, force=self.force, prefix=install_root,
prefix=install_root,
verbose=self.verbose, dry_run=self.dry_run) verbose=self.verbose, dry_run=self.dry_run)
......
...@@ -9,6 +9,7 @@ __revision__ = "$Id$" ...@@ -9,6 +9,7 @@ __revision__ = "$Id$"
import os import os
from distutils.core import Command from distutils.core import Command
from distutils import log
from stat import ST_MODE from stat import ST_MODE
class install_scripts (Command): class install_scripts (Command):
...@@ -48,10 +49,10 @@ class install_scripts (Command): ...@@ -48,10 +49,10 @@ class install_scripts (Command):
# all the scripts we just installed. # all the scripts we just installed.
for file in self.get_outputs(): for file in self.get_outputs():
if self.dry_run: if self.dry_run:
self.announce("changing mode of %s" % file) log.info("changing mode of %s to %o", file, mode)
else: else:
mode = ((os.stat(file)[ST_MODE]) | 0111) & 07777 mode = ((os.stat(file)[ST_MODE]) | 0111) & 07777
self.announce("changing mode of %s to %o" % (file, mode)) log.info("changing mode of %s to %o", file, mode)
os.chmod(file, mode) os.chmod(file, mode)
def get_inputs (self): def get_inputs (self):
......
...@@ -14,6 +14,7 @@ from distutils import dir_util, dep_util, file_util, archive_util ...@@ -14,6 +14,7 @@ from distutils import dir_util, dep_util, file_util, archive_util
from distutils.text_file import TextFile from distutils.text_file import TextFile
from distutils.errors import * from distutils.errors import *
from distutils.filelist import FileList from distutils.filelist import FileList
from distutils import log
def show_formats (): def show_formats ():
...@@ -233,31 +234,17 @@ class sdist (Command): ...@@ -233,31 +234,17 @@ class sdist (Command):
self.warn(("manifest template '%s' does not exist " + self.warn(("manifest template '%s' does not exist " +
"(using default file list)") % "(using default file list)") %
self.template) self.template)
self.filelist.findall() self.filelist.findall()
# Add default file set to 'files'
if self.use_defaults: if self.use_defaults:
self.add_defaults() self.add_defaults()
# Read manifest template if it exists
if template_exists: if template_exists:
self.read_template() self.read_template()
# Prune away any directories that don't belong in the source
# distribution
if self.prune: if self.prune:
self.prune_file_list() self.prune_file_list()
# File list now complete -- sort it so that higher-level files
# come first
self.filelist.sort() self.filelist.sort()
# Remove duplicates from the file list
self.filelist.remove_duplicates() self.filelist.remove_duplicates()
# And write complete file list (including default file set) to
# the manifest.
self.write_manifest() self.write_manifest()
# Don't regenerate the manifest, just read it in. # Don't regenerate the manifest, just read it in.
...@@ -321,13 +308,12 @@ class sdist (Command): ...@@ -321,13 +308,12 @@ class sdist (Command):
def read_template (self): def read_template (self):
"""Read and parse manifest template file named by self.template.
"""Read and parse the manifest template file named by (usually "MANIFEST.in") The parsing and processing is done by
'self.template' (usually "MANIFEST.in"). The parsing and 'self.filelist', which updates itself accordingly.
processing is done by 'self.filelist', which updates itself
accordingly.
""" """
self.announce("reading manifest template '%s'" % self.template) log.info("reading manifest template '%s'", self.template)
template = TextFile(self.template, template = TextFile(self.template,
strip_comments=1, strip_comments=1,
skip_blanks=1, skip_blanks=1,
...@@ -384,7 +370,7 @@ class sdist (Command): ...@@ -384,7 +370,7 @@ class sdist (Command):
fill in 'self.filelist', the list of files to include in the source fill in 'self.filelist', the list of files to include in the source
distribution. distribution.
""" """
self.announce("reading manifest file '%s'" % self.manifest) log.info("reading manifest file '%s'", self.manifest)
manifest = open(self.manifest) manifest = open(self.manifest)
while 1: while 1:
line = manifest.readline() line = manifest.readline()
...@@ -410,8 +396,7 @@ class sdist (Command): ...@@ -410,8 +396,7 @@ class sdist (Command):
# put 'files' there; the 'mkpath()' is just so we don't die # put 'files' there; the 'mkpath()' is just so we don't die
# if the manifest happens to be empty. # if the manifest happens to be empty.
self.mkpath(base_dir) self.mkpath(base_dir)
dir_util.create_tree(base_dir, files, dir_util.create_tree(base_dir, files, dry_run=self.dry_run)
verbose=self.verbose, dry_run=self.dry_run)
# And walk over the list of files, either making a hard link (if # And walk over the list of files, either making a hard link (if
# os.link exists) to each one that doesn't already exist in its # os.link exists) to each one that doesn't already exist in its
...@@ -428,12 +413,12 @@ class sdist (Command): ...@@ -428,12 +413,12 @@ class sdist (Command):
msg = "copying files to %s..." % base_dir msg = "copying files to %s..." % base_dir
if not files: if not files:
self.warn("no files to distribute -- empty manifest?") log.warn("no files to distribute -- empty manifest?")
else: else:
self.announce(msg) log.info(msg)
for file in files: for file in files:
if not os.path.isfile(file): if not os.path.isfile(file):
self.warn("'%s' not a regular file -- skipping" % file) log.warn("'%s' not a regular file -- skipping" % file)
else: else:
dest = os.path.join(base_dir, file) dest = os.path.join(base_dir, file)
self.copy_file(file, dest, link=link) self.copy_file(file, dest, link=link)
...@@ -464,7 +449,7 @@ class sdist (Command): ...@@ -464,7 +449,7 @@ class sdist (Command):
self.archive_files = archive_files self.archive_files = archive_files
if not self.keep_temp: if not self.keep_temp:
dir_util.remove_tree(base_dir, self.verbose, self.dry_run) dir_util.remove_tree(base_dir, dry_run=self.dry_run)
def get_archive_files (self): def get_archive_files (self):
"""Return the list of archive files created when the command """Return the list of archive files created when the command
......
...@@ -100,7 +100,11 @@ def setup (**attrs): ...@@ -100,7 +100,11 @@ def setup (**attrs):
try: try:
_setup_distribution = dist = klass(attrs) _setup_distribution = dist = klass(attrs)
except DistutilsSetupError, msg: except DistutilsSetupError, msg:
raise SystemExit, "error in setup script: %s" % msg if attrs.has_key('name'):
raise SystemExit, "error in %s setup command: %s" % \
(attrs['name'], msg)
else:
raise SystemExit, "error in setup command: %s" % msg
if _setup_stop_after == "init": if _setup_stop_after == "init":
return dist return dist
......
...@@ -50,6 +50,7 @@ from distutils.ccompiler import gen_preprocess_options, gen_lib_options ...@@ -50,6 +50,7 @@ from distutils.ccompiler import gen_preprocess_options, gen_lib_options
from distutils.unixccompiler import UnixCCompiler from distutils.unixccompiler import UnixCCompiler
from distutils.file_util import write_file from distutils.file_util import write_file
from distutils.errors import DistutilsExecError, CompileError, UnknownFileError from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
from distutils import log
class CygwinCCompiler (UnixCCompiler): class CygwinCCompiler (UnixCCompiler):
...@@ -148,7 +149,7 @@ class CygwinCCompiler (UnixCCompiler): ...@@ -148,7 +149,7 @@ class CygwinCCompiler (UnixCCompiler):
src = sources[i] ; obj = objects[i] src = sources[i] ; obj = objects[i]
ext = (os.path.splitext (src))[1] ext = (os.path.splitext (src))[1]
if skip_sources[src]: if skip_sources[src]:
self.announce ("skipping %s (%s up-to-date)" % (src, obj)) log.debug("skipping %s (%s up-to-date)", src, obj)
else: else:
self.mkpath (os.path.dirname (obj)) self.mkpath (os.path.dirname (obj))
if ext == '.rc' or ext == '.res': if ext == '.rc' or ext == '.res':
......
...@@ -9,7 +9,7 @@ __revision__ = "$Id$" ...@@ -9,7 +9,7 @@ __revision__ = "$Id$"
import os import os
from types import * from types import *
from distutils.errors import DistutilsFileError, DistutilsInternalError from distutils.errors import DistutilsFileError, DistutilsInternalError
from distutils import log
# cache for by mkpath() -- in addition to cheapening redundant calls, # cache for by mkpath() -- in addition to cheapening redundant calls,
# eliminates redundant "creating /foo/bar/baz" messages in dry-run mode # eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
...@@ -69,8 +69,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0): ...@@ -69,8 +69,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
if _path_created.get(abs_head): if _path_created.get(abs_head):
continue continue
if verbose: log.info("creating %s", head)
print "creating", head
if not dry_run: if not dry_run:
try: try:
...@@ -105,7 +104,7 @@ def create_tree (base_dir, files, mode=0777, verbose=0, dry_run=0): ...@@ -105,7 +104,7 @@ def create_tree (base_dir, files, mode=0777, verbose=0, dry_run=0):
# Now create them # Now create them
for dir in need_dirs: for dir in need_dirs:
mkpath(dir, mode, verbose, dry_run) mkpath(dir, mode, dry_run=dry_run)
# create_tree () # create_tree ()
...@@ -151,7 +150,7 @@ def copy_tree (src, dst, ...@@ -151,7 +150,7 @@ def copy_tree (src, dst,
"error listing files in '%s': %s" % (src, errstr) "error listing files in '%s': %s" % (src, errstr)
if not dry_run: if not dry_run:
mkpath(dst, verbose=verbose) mkpath(dst)
outputs = [] outputs = []
...@@ -161,21 +160,19 @@ def copy_tree (src, dst, ...@@ -161,21 +160,19 @@ def copy_tree (src, dst,
if preserve_symlinks and os.path.islink(src_name): if preserve_symlinks and os.path.islink(src_name):
link_dest = os.readlink(src_name) link_dest = os.readlink(src_name)
if verbose: log.info("linking %s -> %s", dst_name, link_dest)
print "linking %s -> %s" % (dst_name, link_dest)
if not dry_run: if not dry_run:
os.symlink(link_dest, dst_name) os.symlink(link_dest, dst_name)
outputs.append(dst_name) outputs.append(dst_name)
elif os.path.isdir(src_name): elif os.path.isdir(src_name):
outputs.extend( outputs.extend(
copy_tree(src_name, dst_name, copy_tree(src_name, dst_name, preserve_mode,
preserve_mode, preserve_times, preserve_symlinks, preserve_times, preserve_symlinks, update,
update, verbose, dry_run)) dry_run=dry_run))
else: else:
copy_file(src_name, dst_name, copy_file(src_name, dst_name, preserve_mode,
preserve_mode, preserve_times, preserve_times, update, dry_run=dry_run)
update, None, verbose, dry_run)
outputs.append(dst_name) outputs.append(dst_name)
return outputs return outputs
...@@ -200,8 +197,7 @@ def remove_tree (directory, verbose=0, dry_run=0): ...@@ -200,8 +197,7 @@ def remove_tree (directory, verbose=0, dry_run=0):
from distutils.util import grok_environment_error from distutils.util import grok_environment_error
global _path_created global _path_created
if verbose: log.info("removing '%s' (and everything under it)", directory)
print "removing '%s' (and everything under it)" % directory
if dry_run: if dry_run:
return return
cmdtuples = [] cmdtuples = []
...@@ -214,6 +210,5 @@ def remove_tree (directory, verbose=0, dry_run=0): ...@@ -214,6 +210,5 @@ def remove_tree (directory, verbose=0, dry_run=0):
if _path_created.has_key(abspath): if _path_created.has_key(abspath):
del _path_created[abspath] del _path_created[abspath]
except (IOError, OSError), exc: except (IOError, OSError), exc:
if verbose: log.warn(grok_environment_error(
print grok_environment_error( exc, "error removing %s: " % directory))
exc, "error removing %s: " % directory)
...@@ -15,7 +15,7 @@ from copy import copy ...@@ -15,7 +15,7 @@ from copy import copy
from distutils.errors import * from distutils.errors import *
from distutils.fancy_getopt import FancyGetopt, translate_longopt from distutils.fancy_getopt import FancyGetopt, translate_longopt
from distutils.util import check_environ, strtobool, rfc822_escape from distutils.util import check_environ, strtobool, rfc822_escape
from distutils import log
# Regex to define acceptable Distutils command names. This is not *quite* # Regex to define acceptable Distutils command names. This is not *quite*
# the same as a Python NAME -- I don't allow leading underscores. The fact # the same as a Python NAME -- I don't allow leading underscores. The fact
...@@ -46,7 +46,8 @@ class Distribution: ...@@ -46,7 +46,8 @@ class Distribution:
# since every global option is also valid as a command option -- and we # since every global option is also valid as a command option -- and we
# don't want to pollute the commands with too many options that they # don't want to pollute the commands with too many options that they
# have minimal control over. # have minimal control over.
global_options = [('verbose', 'v', "run verbosely (default)"), # The fourth entry for verbose means that it can be repeated.
global_options = [('verbose', 'v', "run verbosely (default)", 1),
('quiet', 'q', "run quietly (turns verbosity off)"), ('quiet', 'q', "run quietly (turns verbosity off)"),
('dry-run', 'n', "don't actually do anything"), ('dry-run', 'n', "don't actually do anything"),
('help', 'h', "show detailed help message"), ('help', 'h', "show detailed help message"),
...@@ -392,6 +393,7 @@ class Distribution: ...@@ -392,6 +393,7 @@ class Distribution:
parser.set_aliases({'licence': 'license'}) parser.set_aliases({'licence': 'license'})
args = parser.getopt(args=self.script_args, object=self) args = parser.getopt(args=self.script_args, object=self)
option_order = parser.get_option_order() option_order = parser.get_option_order()
log.set_verbosity(self.verbose)
# for display options we return immediately # for display options we return immediately
if self.handle_display_options(option_order): if self.handle_display_options(option_order):
...@@ -876,13 +878,7 @@ class Distribution: ...@@ -876,13 +878,7 @@ class Distribution:
# -- Methods that operate on the Distribution ---------------------- # -- Methods that operate on the Distribution ----------------------
def announce (self, msg, level=1): def announce (self, msg, level=1):
"""Print 'msg' if 'level' is greater than or equal to the verbosity log.debug(msg)
level recorded in the 'verbose' attribute (which, currently, can be
only 0 or 1).
"""
if self.verbose >= level:
print msg
def run_commands (self): def run_commands (self):
"""Run each command that was seen on the setup script command line. """Run each command that was seen on the setup script command line.
...@@ -907,7 +903,7 @@ class Distribution: ...@@ -907,7 +903,7 @@ class Distribution:
if self.have_run.get(command): if self.have_run.get(command):
return return
self.announce("running " + command) log.info("running %s", command)
cmd_obj = self.get_command_obj(command) cmd_obj = self.get_command_obj(command)
cmd_obj.ensure_finalized() cmd_obj.ensure_finalized()
cmd_obj.run() cmd_obj.run()
......
...@@ -28,6 +28,7 @@ from distutils.ccompiler import gen_preprocess_options, gen_lib_options ...@@ -28,6 +28,7 @@ from distutils.ccompiler import gen_preprocess_options, gen_lib_options
from distutils.unixccompiler import UnixCCompiler from distutils.unixccompiler import UnixCCompiler
from distutils.file_util import write_file from distutils.file_util import write_file
from distutils.errors import DistutilsExecError, CompileError, UnknownFileError from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
from distutils import log
class EMXCCompiler (UnixCCompiler): class EMXCCompiler (UnixCCompiler):
...@@ -109,7 +110,7 @@ class EMXCCompiler (UnixCCompiler): ...@@ -109,7 +110,7 @@ class EMXCCompiler (UnixCCompiler):
src = sources[i] ; obj = objects[i] src = sources[i] ; obj = objects[i]
ext = (os.path.splitext (src))[1] ext = (os.path.splitext (src))[1]
if skip_sources[src]: if skip_sources[src]:
self.announce ("skipping %s (%s up-to-date)" % (src, obj)) log.debug("skipping %s (%s up-to-date)", src, obj)
else: else:
self.mkpath (os.path.dirname (obj)) self.mkpath (os.path.dirname (obj))
if ext == '.rc': if ext == '.rc':
......
...@@ -157,13 +157,18 @@ class FancyGetopt: ...@@ -157,13 +157,18 @@ class FancyGetopt:
self.long_opts = [] self.long_opts = []
self.short_opts = [] self.short_opts = []
self.short2long.clear() self.short2long.clear()
self.repeat = {}
for option in self.option_table: for option in self.option_table:
try: if len(option) == 3:
(long, short, help) = option long, short, help = option
except ValueError: repeat = 0
raise DistutilsGetoptError, \ elif len(option) == 4:
"invalid option tuple " + str(option) long, short, help, repeat = option
else:
# the option table is part of the code, so simply
# assert that it is correct
assert "invalid option tuple: %s" % `option`
# Type- and value-check the option names # Type- and value-check the option names
if type(long) is not StringType or len(long) < 2: if type(long) is not StringType or len(long) < 2:
...@@ -177,6 +182,7 @@ class FancyGetopt: ...@@ -177,6 +182,7 @@ class FancyGetopt:
("invalid short option '%s': " ("invalid short option '%s': "
"must a single character or None") % short "must a single character or None") % short
self.repeat[long] = 1
self.long_opts.append(long) self.long_opts.append(long)
if long[-1] == '=': # option takes an argument? if long[-1] == '=': # option takes an argument?
...@@ -232,14 +238,15 @@ class FancyGetopt: ...@@ -232,14 +238,15 @@ class FancyGetopt:
def getopt (self, args=None, object=None): def getopt (self, args=None, object=None):
"""Parse the command-line options in 'args' and store the results """Parse command-line options in args. Store as attributes on object.
as attributes of 'object'. If 'args' is None or not supplied, uses
'sys.argv[1:]'. If 'object' is None or not supplied, creates a new If 'args' is None or not supplied, uses 'sys.argv[1:]'. If
OptionDummy object, stores option values there, and returns a tuple 'object' is None or not supplied, creates a new OptionDummy
(args, object). If 'object' is supplied, it is modified in place object, stores option values there, and returns a tuple (args,
and 'getopt()' just returns 'args'; in both cases, the returned object). If 'object' is supplied, it is modified in place and
'args' is a modified copy of the passed-in 'args' list, which is 'getopt()' just returns 'args'; in both cases, the returned
left untouched. 'args' is a modified copy of the passed-in 'args' list, which
is left untouched.
""" """
if args is None: if args is None:
args = sys.argv[1:] args = sys.argv[1:]
...@@ -253,30 +260,23 @@ class FancyGetopt: ...@@ -253,30 +260,23 @@ class FancyGetopt:
short_opts = string.join(self.short_opts) short_opts = string.join(self.short_opts)
try: try:
(opts, args) = getopt.getopt(args, short_opts, self.long_opts) opts, args = getopt.getopt(args, short_opts, self.long_opts)
except getopt.error, msg: except getopt.error, msg:
raise DistutilsArgError, msg raise DistutilsArgError, msg
for (opt, val) in opts: for opt, val in opts:
if len(opt) == 2 and opt[0] == '-': # it's a short option if len(opt) == 2 and opt[0] == '-': # it's a short option
opt = self.short2long[opt[1]] opt = self.short2long[opt[1]]
elif len(opt) > 2 and opt[0:2] == '--':
opt = opt[2:]
else: else:
raise DistutilsInternalError, \ assert len(opt) > 2 and opt[:2] == '--'
"this can't happen: bad option string '%s'" % opt opt = opt[2:]
alias = self.alias.get(opt) alias = self.alias.get(opt)
if alias: if alias:
opt = alias opt = alias
if not self.takes_arg[opt]: # boolean option? if not self.takes_arg[opt]: # boolean option?
if val != '': # shouldn't have a value! assert val == '', "boolean option can't have value"
raise DistutilsInternalError, \
"this can't happen: bad option value '%s'" % val
alias = self.negative_alias.get(opt) alias = self.negative_alias.get(opt)
if alias: if alias:
opt = alias opt = alias
...@@ -285,13 +285,16 @@ class FancyGetopt: ...@@ -285,13 +285,16 @@ class FancyGetopt:
val = 1 val = 1
attr = self.attr_name[opt] attr = self.attr_name[opt]
# The only repeating option at the moment is 'verbose'.
# It has a negative option -q quiet, which should set verbose = 0.
if val and self.repeat.get(attr) is not None:
val = getattr(object, attr, 0) + 1
setattr(object, attr, val) setattr(object, attr, val)
self.option_order.append((opt, val)) self.option_order.append((opt, val))
# for opts # for opts
if created_object: if created_object:
return (args, object) return args, object
else: else:
return args return args
......
...@@ -9,7 +9,7 @@ __revision__ = "$Id$" ...@@ -9,7 +9,7 @@ __revision__ = "$Id$"
import os import os
from distutils.errors import DistutilsFileError from distutils.errors import DistutilsFileError
from distutils import log
# for generating verbose output in 'copy_file()' # for generating verbose output in 'copy_file()'
_copy_action = { None: 'copying', _copy_action = { None: 'copying',
...@@ -73,7 +73,6 @@ def _copy_file_contents (src, dst, buffer_size=16*1024): ...@@ -73,7 +73,6 @@ def _copy_file_contents (src, dst, buffer_size=16*1024):
# _copy_file_contents() # _copy_file_contents()
def copy_file (src, dst, def copy_file (src, dst,
preserve_mode=1, preserve_mode=1,
preserve_times=1, preserve_times=1,
...@@ -90,8 +89,7 @@ def copy_file (src, dst, ...@@ -90,8 +89,7 @@ def copy_file (src, dst,
'preserve_times' is true (the default), the last-modified and 'preserve_times' is true (the default), the last-modified and
last-access times are copied as well. If 'update' is true, 'src' will last-access times are copied as well. If 'update' is true, 'src' will
only be copied if 'dst' does not exist, or if 'dst' does exist but is only be copied if 'dst' does not exist, or if 'dst' does exist but is
older than 'src'. If 'verbose' is true, then a one-line summary of the older than 'src'.
copy will be printed to stdout.
'link' allows you to make hard links (os.link) or symbolic links 'link' allows you to make hard links (os.link) or symbolic links
(os.symlink) instead of copying: set it to "hard" or "sym"; if it is (os.symlink) instead of copying: set it to "hard" or "sym"; if it is
...@@ -127,20 +125,18 @@ def copy_file (src, dst, ...@@ -127,20 +125,18 @@ def copy_file (src, dst,
dir = os.path.dirname(dst) dir = os.path.dirname(dst)
if update and not newer(src, dst): if update and not newer(src, dst):
if verbose: log.debug("not copying %s (output up-to-date)", src)
print "not copying %s (output up-to-date)" % src return dst, 0
return (dst, 0)
try: try:
action = _copy_action[link] action = _copy_action[link]
except KeyError: except KeyError:
raise ValueError, \ raise ValueError, \
"invalid value '%s' for 'link' argument" % link "invalid value '%s' for 'link' argument" % link
if verbose: if os.path.basename(dst) == os.path.basename(src):
if os.path.basename(dst) == os.path.basename(src): log.info("%s %s -> %s", action, src, dir)
print "%s %s -> %s" % (action, src, dir) else:
else: log.info("%s %s -> %s", action, src, dst)
print "%s %s -> %s" % (action, src, dst)
if dry_run: if dry_run:
return (dst, 1) return (dst, 1)
...@@ -197,8 +193,7 @@ def move_file (src, dst, ...@@ -197,8 +193,7 @@ def move_file (src, dst,
from os.path import exists, isfile, isdir, basename, dirname from os.path import exists, isfile, isdir, basename, dirname
import errno import errno
if verbose: log.info("moving %s -> %s", src, dst)
print "moving %s -> %s" % (src, dst)
if dry_run: if dry_run:
return dst return dst
......
...@@ -37,27 +37,19 @@ class FileList: ...@@ -37,27 +37,19 @@ class FileList:
def __init__(self, def __init__(self,
warn=None, warn=None,
debug_print=None): debug_print=None):
# use standard warning and debug functions if no other given # ignore argument to FileList, but keep them for backwards
self.warn = warn or self.__warn # compatibility
self.debug_print = debug_print or self.__debug_print
self.allfiles = None self.allfiles = None
self.files = [] self.files = []
def set_allfiles (self, allfiles): def set_allfiles (self, allfiles):
self.allfiles = allfiles self.allfiles = allfiles
def findall (self, dir=os.curdir): def findall (self, dir=os.curdir):
self.allfiles = findall(dir) self.allfiles = findall(dir)
def debug_print (self, msg):
# -- Fallback warning/debug functions ------------------------------
def __warn (self, msg):
sys.stderr.write("warning: %s\n" % msg)
def __debug_print (self, msg):
"""Print 'msg' to stdout if the global DEBUG (taken from the """Print 'msg' to stdout if the global DEBUG (taken from the
DISTUTILS_DEBUG environment variable) flag is true. DISTUTILS_DEBUG environment variable) flag is true.
""" """
...@@ -65,7 +57,6 @@ class FileList: ...@@ -65,7 +57,6 @@ class FileList:
if DEBUG: if DEBUG:
print msg print msg
# -- List-like methods --------------------------------------------- # -- List-like methods ---------------------------------------------
def append (self, item): def append (self, item):
...@@ -87,8 +78,8 @@ class FileList: ...@@ -87,8 +78,8 @@ class FileList:
def remove_duplicates (self): def remove_duplicates (self):
# Assumes list has been sorted! # Assumes list has been sorted!
for i in range(len(self.files)-1, 0, -1): for i in range(len(self.files) - 1, 0, -1):
if self.files[i] == self.files[i-1]: if self.files[i] == self.files[i - 1]:
del self.files[i] del self.files[i]
...@@ -147,61 +138,60 @@ class FileList: ...@@ -147,61 +138,60 @@ class FileList:
self.debug_print("include " + string.join(patterns)) self.debug_print("include " + string.join(patterns))
for pattern in patterns: for pattern in patterns:
if not self.include_pattern(pattern, anchor=1): if not self.include_pattern(pattern, anchor=1):
self.warn("no files found matching '%s'" % pattern) log.warn("warning: no files found matching '%s'",
pattern)
elif action == 'exclude': elif action == 'exclude':
self.debug_print("exclude " + string.join(patterns)) self.debug_print("exclude " + string.join(patterns))
for pattern in patterns: for pattern in patterns:
if not self.exclude_pattern(pattern, anchor=1): if not self.exclude_pattern(pattern, anchor=1):
self.warn( log.warn(("warning: no previously-included files "
"no previously-included files found matching '%s'"% "found matching '%s'"), pattern)
pattern)
elif action == 'global-include': elif action == 'global-include':
self.debug_print("global-include " + string.join(patterns)) self.debug_print("global-include " + string.join(patterns))
for pattern in patterns: for pattern in patterns:
if not self.include_pattern(pattern, anchor=0): if not self.include_pattern(pattern, anchor=0):
self.warn(("no files found matching '%s' " + log.warn(("warning: no files found matching '%s' " +
"anywhere in distribution") % "anywhere in distribution"), pattern)
pattern)
elif action == 'global-exclude': elif action == 'global-exclude':
self.debug_print("global-exclude " + string.join(patterns)) self.debug_print("global-exclude " + string.join(patterns))
for pattern in patterns: for pattern in patterns:
if not self.exclude_pattern(pattern, anchor=0): if not self.exclude_pattern(pattern, anchor=0):
self.warn(("no previously-included files matching '%s' " + log.warn(("warning: no previously-included files matching "
"found anywhere in distribution") % "'%s' found anywhere in distribution"),
pattern) pattern)
elif action == 'recursive-include': elif action == 'recursive-include':
self.debug_print("recursive-include %s %s" % self.debug_print("recursive-include %s %s" %
(dir, string.join(patterns))) (dir, string.join(patterns)))
for pattern in patterns: for pattern in patterns:
if not self.include_pattern(pattern, prefix=dir): if not self.include_pattern(pattern, prefix=dir):
self.warn(("no files found matching '%s' " + log.warn(("warngin: no files found matching '%s' " +
"under directory '%s'") % "under directory '%s'"),
(pattern, dir)) pattern, dir)
elif action == 'recursive-exclude': elif action == 'recursive-exclude':
self.debug_print("recursive-exclude %s %s" % self.debug_print("recursive-exclude %s %s" %
(dir, string.join(patterns))) (dir, string.join(patterns)))
for pattern in patterns: for pattern in patterns:
if not self.exclude_pattern(pattern, prefix=dir): if not self.exclude_pattern(pattern, prefix=dir):
self.warn(("no previously-included files matching '%s' " + log.warn(("warning: no previously-included files matching "
"found under directory '%s'") % "'%s' found under directory '%s'"),
(pattern, dir)) pattern, dir)
elif action == 'graft': elif action == 'graft':
self.debug_print("graft " + dir_pattern) self.debug_print("graft " + dir_pattern)
if not self.include_pattern(None, prefix=dir_pattern): if not self.include_pattern(None, prefix=dir_pattern):
self.warn("no directories found matching '%s'" % dir_pattern) log.warn("warning: no directories found matching '%s'",
dir_pattern)
elif action == 'prune': elif action == 'prune':
self.debug_print("prune " + dir_pattern) self.debug_print("prune " + dir_pattern)
if not self.exclude_pattern(None, prefix=dir_pattern): if not self.exclude_pattern(None, prefix=dir_pattern):
self.warn(("no previously-included directories found " + log.warn(("no previously-included directories found " +
"matching '%s'") % "matching '%s'"), dir_pattern)
dir_pattern)
else: else:
raise DistutilsInternalError, \ raise DistutilsInternalError, \
"this cannot happen: invalid action '%s'" % action "this cannot happen: invalid action '%s'" % action
......
...@@ -17,6 +17,7 @@ from distutils.errors import \ ...@@ -17,6 +17,7 @@ from distutils.errors import \
CompileError, LibError, LinkError CompileError, LibError, LinkError
from distutils.ccompiler import \ from distutils.ccompiler import \
CCompiler, gen_preprocess_options, gen_lib_options CCompiler, gen_preprocess_options, gen_lib_options
from distutils import log
_can_read_reg = 0 _can_read_reg = 0
try: try:
...@@ -305,7 +306,7 @@ class MSVCCompiler (CCompiler) : ...@@ -305,7 +306,7 @@ class MSVCCompiler (CCompiler) :
ext = (os.path.splitext (src))[1] ext = (os.path.splitext (src))[1]
if skip_sources[src]: if skip_sources[src]:
self.announce ("skipping %s (%s up-to-date)" % (src, obj)) log.debug("skipping %s (%s up-to-date)", src, obj)
else: else:
self.mkpath (os.path.dirname (obj)) self.mkpath (os.path.dirname (obj))
...@@ -403,7 +404,7 @@ class MSVCCompiler (CCompiler) : ...@@ -403,7 +404,7 @@ class MSVCCompiler (CCompiler) :
raise LibError, msg raise LibError, msg
else: else:
self.announce ("skipping %s (up-to-date)" % output_filename) log.debug("skipping %s (up-to-date)", output_filename)
# create_static_lib () # create_static_lib ()
...@@ -480,7 +481,7 @@ class MSVCCompiler (CCompiler) : ...@@ -480,7 +481,7 @@ class MSVCCompiler (CCompiler) :
raise LinkError, msg raise LinkError, msg
else: else:
self.announce ("skipping %s (up-to-date)" % output_filename) log.debug("skipping %s (up-to-date)", output_filename)
# link () # link ()
......
...@@ -13,6 +13,7 @@ from distutils.ccompiler import \ ...@@ -13,6 +13,7 @@ from distutils.ccompiler import \
CCompiler, gen_preprocess_options, gen_lib_options CCompiler, gen_preprocess_options, gen_lib_options
import distutils.util import distutils.util
import distutils.dir_util import distutils.dir_util
from distutils import log
import mkcwproject import mkcwproject
class MWerksCompiler (CCompiler) : class MWerksCompiler (CCompiler) :
...@@ -132,8 +133,8 @@ class MWerksCompiler (CCompiler) : ...@@ -132,8 +133,8 @@ class MWerksCompiler (CCompiler) :
exportname = basename + '.mcp.exp' exportname = basename + '.mcp.exp'
prefixname = 'mwerks_%s_config.h'%basename prefixname = 'mwerks_%s_config.h'%basename
# Create the directories we need # Create the directories we need
distutils.dir_util.mkpath(build_temp, self.verbose, self.dry_run) distutils.dir_util.mkpath(build_temp, dry_run=self.dry_run)
distutils.dir_util.mkpath(output_dir, self.verbose, self.dry_run) distutils.dir_util.mkpath(output_dir, dry_run=self.dry_run)
# And on to filling in the parameters for the project builder # And on to filling in the parameters for the project builder
settings = {} settings = {}
settings['mac_exportname'] = exportname settings['mac_exportname'] = exportname
...@@ -159,8 +160,7 @@ class MWerksCompiler (CCompiler) : ...@@ -159,8 +160,7 @@ class MWerksCompiler (CCompiler) :
return return
# Build the export file # Build the export file
exportfilename = os.path.join(build_temp, exportname) exportfilename = os.path.join(build_temp, exportname)
if self.verbose: log.debug("\tCreate export file", exportfilename)
print '\tCreate export file', exportfilename
fp = open(exportfilename, 'w') fp = open(exportfilename, 'w')
fp.write('%s\n'%export_symbols[0]) fp.write('%s\n'%export_symbols[0])
fp.close() fp.close()
...@@ -181,8 +181,7 @@ class MWerksCompiler (CCompiler) : ...@@ -181,8 +181,7 @@ class MWerksCompiler (CCompiler) :
# because we pass this pathname to CodeWarrior in an AppleEvent, and CW # because we pass this pathname to CodeWarrior in an AppleEvent, and CW
# doesn't have a clue about our working directory. # doesn't have a clue about our working directory.
xmlfilename = os.path.join(os.getcwd(), os.path.join(build_temp, xmlname)) xmlfilename = os.path.join(os.getcwd(), os.path.join(build_temp, xmlname))
if self.verbose: log.debug("\tCreate XML file", xmlfilename)
print '\tCreate XML file', xmlfilename
xmlbuilder = mkcwproject.cwxmlgen.ProjectBuilder(settings) xmlbuilder = mkcwproject.cwxmlgen.ProjectBuilder(settings)
xmlbuilder.generate() xmlbuilder.generate()
xmldata = settings['tmp_projectxmldata'] xmldata = settings['tmp_projectxmldata']
...@@ -191,12 +190,10 @@ class MWerksCompiler (CCompiler) : ...@@ -191,12 +190,10 @@ class MWerksCompiler (CCompiler) :
fp.close() fp.close()
# Generate the project. Again a full pathname. # Generate the project. Again a full pathname.
projectfilename = os.path.join(os.getcwd(), os.path.join(build_temp, projectname)) projectfilename = os.path.join(os.getcwd(), os.path.join(build_temp, projectname))
if self.verbose: log.debug('\tCreate project file', projectfilename)
print '\tCreate project file', projectfilename
mkcwproject.makeproject(xmlfilename, projectfilename) mkcwproject.makeproject(xmlfilename, projectfilename)
# And build it # And build it
if self.verbose: log.debug('\tBuild project')
print '\tBuild project'
mkcwproject.buildproject(projectfilename) mkcwproject.buildproject(projectfilename)
def _filename_to_abs(self, filename): def _filename_to_abs(self, filename):
......
...@@ -12,7 +12,7 @@ __revision__ = "$Id$" ...@@ -12,7 +12,7 @@ __revision__ = "$Id$"
import sys, os, string import sys, os, string
from distutils.errors import * from distutils.errors import *
from distutils import log
def spawn (cmd, def spawn (cmd,
search_path=1, search_path=1,
...@@ -27,19 +27,18 @@ def spawn (cmd, ...@@ -27,19 +27,18 @@ def spawn (cmd,
If 'search_path' is true (the default), the system's executable search If 'search_path' is true (the default), the system's executable search
path will be used to find the program; otherwise, cmd[0] must be the path will be used to find the program; otherwise, cmd[0] must be the
exact path to the executable. If 'verbose' is true, a one-line summary exact path to the executable.If 'dry_run' is true,
of the command will be printed before it is run. If 'dry_run' is true,
the command will not actually be run. the command will not actually be run.
Raise DistutilsExecError if running the program fails in any way; just Raise DistutilsExecError if running the program fails in any way; just
return on success. return on success.
""" """
if os.name == 'posix': if os.name == 'posix':
_spawn_posix(cmd, search_path, verbose, dry_run) _spawn_posix(cmd, search_path, dry_run=dry_run)
elif os.name == 'nt': elif os.name == 'nt':
_spawn_nt(cmd, search_path, verbose, dry_run) _spawn_nt(cmd, search_path, dry_run=dry_run)
elif os.name == 'os2': elif os.name == 'os2':
_spawn_os2(cmd, search_path, verbose, dry_run) _spawn_os2(cmd, search_path, dry_run=dry_run)
else: else:
raise DistutilsPlatformError, \ raise DistutilsPlatformError, \
"don't know how to spawn programs on platform '%s'" % os.name "don't know how to spawn programs on platform '%s'" % os.name
...@@ -74,8 +73,7 @@ def _spawn_nt (cmd, ...@@ -74,8 +73,7 @@ def _spawn_nt (cmd,
if search_path: if search_path:
# either we find one or it stays the same # either we find one or it stays the same
executable = find_executable(executable) or executable executable = find_executable(executable) or executable
if verbose: log.info(string.join([executable] + cmd[1:], ' '))
print string.join([executable] + cmd[1:], ' ')
if not dry_run: if not dry_run:
# spawn for NT requires a full path to the .exe # spawn for NT requires a full path to the .exe
try: try:
...@@ -100,8 +98,7 @@ def _spawn_os2 (cmd, ...@@ -100,8 +98,7 @@ def _spawn_os2 (cmd,
if search_path: if search_path:
# either we find one or it stays the same # either we find one or it stays the same
executable = find_executable(executable) or executable executable = find_executable(executable) or executable
if verbose: log.info(string.join([executable] + cmd[1:], ' '))
print string.join([executable] + cmd[1:], ' ')
if not dry_run: if not dry_run:
# spawnv for OS/2 EMX requires a full path to the .exe # spawnv for OS/2 EMX requires a full path to the .exe
try: try:
...@@ -122,8 +119,7 @@ def _spawn_posix (cmd, ...@@ -122,8 +119,7 @@ def _spawn_posix (cmd,
verbose=0, verbose=0,
dry_run=0): dry_run=0):
if verbose: log.info(string.join(cmd, ' '))
print string.join(cmd, ' ')
if dry_run: if dry_run:
return return
exec_fn = search_path and os.execvp or os.execv exec_fn = search_path and os.execvp or os.execv
......
...@@ -26,6 +26,7 @@ from distutils.ccompiler import \ ...@@ -26,6 +26,7 @@ from distutils.ccompiler import \
CCompiler, gen_preprocess_options, gen_lib_options CCompiler, gen_preprocess_options, gen_lib_options
from distutils.errors import \ from distutils.errors import \
DistutilsExecError, CompileError, LibError, LinkError DistutilsExecError, CompileError, LibError, LinkError
from distutils import log
# XXX Things not currently handled: # XXX Things not currently handled:
# * optimization/debug/warning flags; we just use whatever's in Python's # * optimization/debug/warning flags; we just use whatever's in Python's
...@@ -147,7 +148,7 @@ class UnixCCompiler (CCompiler): ...@@ -147,7 +148,7 @@ class UnixCCompiler (CCompiler):
for i in range(len(sources)): for i in range(len(sources)):
src = sources[i] ; obj = objects[i] src = sources[i] ; obj = objects[i]
if skip_sources[src]: if skip_sources[src]:
self.announce("skipping %s (%s up-to-date)" % (src, obj)) log.debug("skipping %s (%s up-to-date)", src, obj)
else: else:
self.mkpath(os.path.dirname(obj)) self.mkpath(os.path.dirname(obj))
try: try:
...@@ -191,7 +192,7 @@ class UnixCCompiler (CCompiler): ...@@ -191,7 +192,7 @@ class UnixCCompiler (CCompiler):
except DistutilsExecError, msg: except DistutilsExecError, msg:
raise LibError, msg raise LibError, msg
else: else:
self.announce("skipping %s (up-to-date)" % output_filename) log.debug("skipping %s (up-to-date)", output_filename)
# create_static_lib () # create_static_lib ()
...@@ -240,7 +241,7 @@ class UnixCCompiler (CCompiler): ...@@ -240,7 +241,7 @@ class UnixCCompiler (CCompiler):
except DistutilsExecError, msg: except DistutilsExecError, msg:
raise LinkError, msg raise LinkError, msg
else: else:
self.announce("skipping %s (up-to-date)" % output_filename) log.debug("skipping %s (up-to-date)", output_filename)
# link () # link ()
......
...@@ -12,7 +12,7 @@ import sys, os, string, re ...@@ -12,7 +12,7 @@ import sys, os, string, re
from distutils.errors import DistutilsPlatformError from distutils.errors import DistutilsPlatformError
from distutils.dep_util import newer from distutils.dep_util import newer
from distutils.spawn import spawn from distutils.spawn import spawn
from distutils import log
def get_platform (): def get_platform ():
"""Return a string that identifies the current platform. This is used """Return a string that identifies the current platform. This is used
...@@ -275,33 +275,27 @@ def split_quoted (s): ...@@ -275,33 +275,27 @@ def split_quoted (s):
def execute (func, args, msg=None, verbose=0, dry_run=0): def execute (func, args, msg=None, verbose=0, dry_run=0):
"""Perform some action that affects the outside world (eg. by writing """Perform some action that affects the outside world (eg. by
to the filesystem). Such actions are special because they are disabled writing to the filesystem). Such actions are special because they
by the 'dry_run' flag, and announce themselves if 'verbose' is true. are disabled by the 'dry_run' flag. This method takes care of all
This method takes care of all that bureaucracy for you; all you have to that bureaucracy for you; all you have to do is supply the
do is supply the function to call and an argument tuple for it (to function to call and an argument tuple for it (to embody the
embody the "external action" being performed), and an optional message "external action" being performed), and an optional message to
to print. print.
""" """
# Generate a message if we weren't passed one
if msg is None: if msg is None:
msg = "%s%s" % (func.__name__, `args`) msg = "%s%s" % (func.__name__, `args`)
if msg[-2:] == ',)': # correct for singleton tuple if msg[-2:] == ',)': # correct for singleton tuple
msg = msg[0:-2] + ')' msg = msg[0:-2] + ')'
# Print it if verbosity level is high enough log.info(msg)
if verbose:
print msg
# And do it, as long as we're not in dry-run mode
if not dry_run: if not dry_run:
apply(func, args) apply(func, args)
# execute()
def strtobool (val): def strtobool (val):
"""Convert a string representation of truth to true (1) or false (0). """Convert a string representation of truth to true (1) or false (0).
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else. 'val' is anything else.
...@@ -337,8 +331,8 @@ def byte_compile (py_files, ...@@ -337,8 +331,8 @@ def byte_compile (py_files,
prepended (after 'prefix' is stripped). You can supply either or both prepended (after 'prefix' is stripped). You can supply either or both
(or neither) of 'prefix' and 'base_dir', as you wish. (or neither) of 'prefix' and 'base_dir', as you wish.
If 'verbose' is true, prints out a report of each file. If 'dry_run' If 'dry_run' is true, doesn't actually do anything that would
is true, doesn't actually do anything that would affect the filesystem. affect the filesystem.
Byte-compilation is either done directly in this interpreter process Byte-compilation is either done directly in this interpreter process
with the standard py_compile module, or indirectly by writing a with the standard py_compile module, or indirectly by writing a
...@@ -367,8 +361,7 @@ def byte_compile (py_files, ...@@ -367,8 +361,7 @@ def byte_compile (py_files,
if not direct: if not direct:
from tempfile import mktemp from tempfile import mktemp
script_name = mktemp(".py") script_name = mktemp(".py")
if verbose: log.info("writing byte-compilation script '%s'", script_name)
print "writing byte-compilation script '%s'" % script_name
if not dry_run: if not dry_run:
script = open(script_name, "w") script = open(script_name, "w")
...@@ -406,9 +399,9 @@ byte_compile(files, optimize=%s, force=%s, ...@@ -406,9 +399,9 @@ byte_compile(files, optimize=%s, force=%s,
cmd.insert(1, "-O") cmd.insert(1, "-O")
elif optimize == 2: elif optimize == 2:
cmd.insert(1, "-OO") cmd.insert(1, "-OO")
spawn(cmd, verbose=verbose, dry_run=dry_run) spawn(cmd, dry_run=dry_run)
execute(os.remove, (script_name,), "removing %s" % script_name, execute(os.remove, (script_name,), "removing %s" % script_name,
verbose=verbose, dry_run=dry_run) dry_run=dry_run)
# "Direct" byte-compilation: use the py_compile module to compile # "Direct" byte-compilation: use the py_compile module to compile
# right here, right now. Note that the script generated in indirect # right here, right now. Note that the script generated in indirect
...@@ -440,14 +433,12 @@ byte_compile(files, optimize=%s, force=%s, ...@@ -440,14 +433,12 @@ byte_compile(files, optimize=%s, force=%s,
cfile_base = os.path.basename(cfile) cfile_base = os.path.basename(cfile)
if direct: if direct:
if force or newer(file, cfile): if force or newer(file, cfile):
if verbose: log.info("byte-compiling %s to %s", file, cfile_base)
print "byte-compiling %s to %s" % (file, cfile_base)
if not dry_run: if not dry_run:
compile(file, cfile, dfile) compile(file, cfile, dfile)
else: else:
if verbose: log.debug("skipping byte-compilation of %s to %s",
print "skipping byte-compilation of %s to %s" % \ file, cfile_base)
(file, cfile_base)
# byte_compile () # byte_compile ()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment