diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-06-04 20:14:43 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-06-04 20:14:43 (GMT) |
commit | cd8a1148e19116db109f27d26c02e1de536dc76e (patch) | |
tree | e3969bc16f8ef0c540f1d0e72fb0da711344d758 /Lib/distutils/cmd.py | |
parent | 6fa82a34775576b90c8ec38e8968dfbb0b02e11d (diff) | |
download | cpython-cd8a1148e19116db109f27d26c02e1de536dc76e.zip cpython-cd8a1148e19116db109f27d26c02e1de536dc76e.tar.gz cpython-cd8a1148e19116db109f27d26c02e1de536dc76e.tar.bz2 |
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.
Diffstat (limited to 'Lib/distutils/cmd.py')
-rw-r--r-- | Lib/distutils/cmd.py | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/Lib/distutils/cmd.py b/Lib/distutils/cmd.py index 65060d6..25ff302 100644 --- a/Lib/distutils/cmd.py +++ b/Lib/distutils/cmd.py @@ -13,7 +13,7 @@ import sys, os, string, re from types import * from distutils.errors import * from distutils import util, dir_util, file_util, archive_util, dep_util - +from distutils import log class Command: """Abstract base class for defining command classes, the "worker bees" @@ -72,11 +72,15 @@ class Command: # commands fallback on the Distribution's behaviour. None means # "not defined, check self.distribution's copy", while 0 or 1 mean # false and true (duh). Note that this means figuring out the real - # value of each flag is a touch complicated -- hence "self.verbose" - # (etc.) will be handled by __getattr__, below. - self._verbose = None + # value of each flag is a touch complicated -- hence "self._dry_run" + # will be handled by __getattr__, below. + # XXX This needs to be fixed. 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 # timestamps, but methods defined *here* assume that # 'self.force' exists for all commands. So define it here @@ -96,8 +100,10 @@ class Command: # __init__ () + # XXX A more explicit way to customize dry_run would be better. + def __getattr__ (self, attr): - if attr in ('verbose', 'dry_run'): + if attr == 'dry_run': myval = getattr(self, "_" + attr) if myval is None: return getattr(self.distribution, attr) @@ -186,9 +192,7 @@ class Command: """If the current verbosity level is of greater than or equal to 'level' print 'msg' to stdout. """ - if self.verbose >= level: - print msg - sys.stdout.flush() + log.debug(msg) def debug_print (self, msg): """Print 'msg' to stdout if the global DEBUG (taken from the @@ -352,12 +356,11 @@ class Command: 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): - dir_util.mkpath(name, mode, - self.verbose, self.dry_run) + dir_util.mkpath(name, mode, dry_run=self.dry_run) def copy_file (self, infile, outfile, @@ -371,8 +374,7 @@ class Command: preserve_mode, preserve_times, not self.force, link, - self.verbose >= level, - self.dry_run) + dry_run=self.dry_run) def copy_tree (self, infile, outfile, @@ -385,30 +387,21 @@ class Command: infile, outfile, preserve_mode,preserve_times,preserve_symlinks, not self.force, - self.verbose >= level, - self.dry_run) - + dry_run=self.dry_run) def move_file (self, src, dst, level=1): - """Move a file respecting verbose and dry-run flags.""" - return file_util.move_file(src, dst, - self.verbose >= level, - self.dry_run) - + """Move a file respectin dry-run flag.""" + return file_util.move_file(src, dst, dry_run = self.dry_run) 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 - spawn(cmd, search_path, - self.verbose >= level, - self.dry_run) - + spawn(cmd, search_path, dry_run= self.dry_run) def make_archive (self, base_name, format, root_dir=None, base_dir=None): return archive_util.make_archive( - base_name, format, root_dir, base_dir, - self.verbose, self.dry_run) + base_name, format, root_dir, base_dir, dry_run=self.dry_run) def make_file (self, infiles, outfile, func, args, @@ -443,7 +436,7 @@ class Command: # Otherwise, print the "skip" message else: - self.announce(skip_msg, level) + log.debug(skip_msg) # make_file () |