summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/fancy_getopt.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2002-06-04 20:14:43 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2002-06-04 20:14:43 (GMT)
commitcd8a1148e19116db109f27d26c02e1de536dc76e (patch)
treee3969bc16f8ef0c540f1d0e72fb0da711344d758 /Lib/distutils/fancy_getopt.py
parent6fa82a34775576b90c8ec38e8968dfbb0b02e11d (diff)
downloadcpython-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/fancy_getopt.py')
-rw-r--r--Lib/distutils/fancy_getopt.py57
1 files changed, 30 insertions, 27 deletions
diff --git a/Lib/distutils/fancy_getopt.py b/Lib/distutils/fancy_getopt.py
index e65302f..fe9b0d4 100644
--- a/Lib/distutils/fancy_getopt.py
+++ b/Lib/distutils/fancy_getopt.py
@@ -157,13 +157,18 @@ class FancyGetopt:
self.long_opts = []
self.short_opts = []
self.short2long.clear()
+ self.repeat = {}
for option in self.option_table:
- try:
- (long, short, help) = option
- except ValueError:
- raise DistutilsGetoptError, \
- "invalid option tuple " + str(option)
+ if len(option) == 3:
+ long, short, help = option
+ repeat = 0
+ elif len(option) == 4:
+ 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
if type(long) is not StringType or len(long) < 2:
@@ -177,6 +182,7 @@ class FancyGetopt:
("invalid short option '%s': "
"must a single character or None") % short
+ self.repeat[long] = 1
self.long_opts.append(long)
if long[-1] == '=': # option takes an argument?
@@ -232,14 +238,15 @@ class FancyGetopt:
def getopt (self, args=None, object=None):
- """Parse the command-line options in 'args' and store the results
- 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
- OptionDummy object, stores option values there, and returns a tuple
- (args, object). If 'object' is supplied, it is modified in place
- and 'getopt()' just returns 'args'; in both cases, the returned
- 'args' is a modified copy of the passed-in 'args' list, which is
- left untouched.
+ """Parse command-line options in args. Store as attributes on object.
+
+ If 'args' is None or not supplied, uses 'sys.argv[1:]'. If
+ 'object' is None or not supplied, creates a new OptionDummy
+ object, stores option values there, and returns a tuple (args,
+ object). If 'object' is supplied, it is modified in place and
+ 'getopt()' just returns 'args'; in both cases, the returned
+ 'args' is a modified copy of the passed-in 'args' list, which
+ is left untouched.
"""
if args is None:
args = sys.argv[1:]
@@ -253,30 +260,23 @@ class FancyGetopt:
short_opts = string.join(self.short_opts)
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:
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
opt = self.short2long[opt[1]]
-
- elif len(opt) > 2 and opt[0:2] == '--':
- opt = opt[2:]
-
else:
- raise DistutilsInternalError, \
- "this can't happen: bad option string '%s'" % opt
+ assert len(opt) > 2 and opt[:2] == '--'
+ opt = opt[2:]
alias = self.alias.get(opt)
if alias:
opt = alias
if not self.takes_arg[opt]: # boolean option?
- if val != '': # shouldn't have a value!
- raise DistutilsInternalError, \
- "this can't happen: bad option value '%s'" % val
-
+ assert val == '', "boolean option can't have value"
alias = self.negative_alias.get(opt)
if alias:
opt = alias
@@ -285,13 +285,16 @@ class FancyGetopt:
val = 1
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)
self.option_order.append((opt, val))
# for opts
-
if created_object:
- return (args, object)
+ return args, object
else:
return args