Kaydet (Commit) 071ed767 authored tarafından Greg Ward's avatar Greg Ward

Standardize whitespace in function calls.

üst 449f5568
......@@ -59,13 +59,13 @@ class Command:
# late import because of mutual dependence between these classes
from distutils.dist import Distribution
if not isinstance (dist, Distribution):
if not isinstance(dist, Distribution):
raise TypeError, "dist must be a Distribution instance"
if self.__class__ is Command:
raise RuntimeError, "Command is an abstract class"
self.distribution = dist
self.initialize_options ()
self.initialize_options()
# Per-command versions of the global flags, so that the user can
# customize Distutils' behaviour command-by-command and let some
......@@ -98,9 +98,9 @@ class Command:
def __getattr__ (self, attr):
if attr in ('verbose', 'dry_run'):
myval = getattr (self, "_" + attr)
myval = getattr(self, "_" + attr)
if myval is None:
return getattr (self.distribution, attr)
return getattr(self.distribution, attr)
else:
return myval
else:
......@@ -109,7 +109,7 @@ class Command:
def ensure_finalized (self):
if not self.finalized:
self.finalize_options ()
self.finalize_options()
self.finalized = 1
......@@ -273,7 +273,7 @@ class Command:
# -- Convenience methods for commands ------------------------------
def get_command_name (self):
if hasattr (self, 'command_name'):
if hasattr(self, 'command_name'):
return self.command_name
else:
return self.__class__.__name__
......@@ -296,12 +296,12 @@ class Command:
# Option_pairs: list of (src_option, dst_option) tuples
src_cmd_obj = self.distribution.get_command_obj (src_cmd)
src_cmd_obj.ensure_finalized ()
src_cmd_obj = self.distribution.get_command_obj(src_cmd)
src_cmd_obj.ensure_finalized()
for (src_option, dst_option) in option_pairs:
if getattr (self, dst_option) is None:
setattr (self, dst_option,
getattr (src_cmd_obj, src_option))
if getattr(self, dst_option) is None:
setattr(self, dst_option,
getattr(src_cmd_obj, src_option))
def get_finalized_command (self, command, create=1):
......@@ -310,8 +310,8 @@ class Command:
'command', call its 'ensure_finalized()' method, and return the
finalized command object.
"""
cmd_obj = self.distribution.get_command_obj (command, create)
cmd_obj.ensure_finalized ()
cmd_obj = self.distribution.get_command_obj(command, create)
cmd_obj.ensure_finalized()
return cmd_obj
# XXX rename to 'get_reinitialized_command()'? (should do the
......@@ -325,7 +325,7 @@ class Command:
Distribution, which creates and finalizes the command object if
necessary and then invokes its 'run()' method.
"""
self.distribution.run_command (command)
self.distribution.run_command(command)
def get_sub_commands (self):
......@@ -345,8 +345,8 @@ class Command:
# -- External world manipulation -----------------------------------
def warn (self, msg):
sys.stderr.write ("warning: %s: %s\n" %
(self.get_command_name(), msg))
sys.stderr.write("warning: %s: %s\n" %
(self.get_command_name(), msg))
def execute (self, func, args, msg=None, level=1):
......@@ -389,17 +389,17 @@ class Command:
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)
return file_util.move_file(src, dst,
self.verbose >= level,
self.dry_run)
def spawn (self, cmd, search_path=1, level=1):
"""Spawn an external command respecting verbose and dry-run flags."""
from distutils.spawn import spawn
spawn (cmd, search_path,
self.verbose >= level,
self.dry_run)
spawn(cmd, search_path,
self.verbose >= level,
self.dry_run)
def make_archive (self, base_name, format,
......@@ -421,15 +421,15 @@ class Command:
"""
if exec_msg is None:
exec_msg = "generating %s from %s" % \
(outfile, string.join (infiles, ', '))
(outfile, string.join(infiles, ', '))
if skip_msg is None:
skip_msg = "skipping %s (inputs unchanged)" % outfile
# Allow 'infiles' to be a single string
if type (infiles) is StringType:
if type(infiles) is StringType:
infiles = (infiles,)
elif type (infiles) not in (ListType, TupleType):
elif type(infiles) not in (ListType, TupleType):
raise TypeError, \
"'infiles' must be a string, or a list or tuple of strings"
......@@ -437,11 +437,11 @@ class Command:
# exist, is out-of-date, or the 'force' flag is true) then
# perform the action that presumably regenerates it
if self.force or dep_util.newer_group (infiles, outfile):
self.execute (func, args, exec_msg, level)
self.execute(func, args, exec_msg, level)
# Otherwise, print the "skip" message
else:
self.announce (skip_msg, level)
self.announce(skip_msg, level)
# make_file ()
......
......@@ -40,21 +40,21 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
# the creation of the whole path? (quite easy to do the latter since
# we're not using a recursive algorithm)
name = os.path.normpath (name)
name = os.path.normpath(name)
created_dirs = []
if os.path.isdir (name) or name == '':
if os.path.isdir(name) or name == '':
return created_dirs
if _path_created.get (name):
if _path_created.get(name):
return created_dirs
(head, tail) = os.path.split (name)
(head, tail) = os.path.split(name)
tails = [tail] # stack of lone dirs to create
while head and tail and not os.path.isdir (head):
while head and tail and not os.path.isdir(head):
#print "splitting '%s': " % head,
(head, tail) = os.path.split (head)
(head, tail) = os.path.split(head)
#print "to ('%s','%s')" % (head, tail)
tails.insert (0, tail) # push next higher dir onto stack
tails.insert(0, tail) # push next higher dir onto stack
#print "stack of tails:", tails
......@@ -63,8 +63,8 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
# that does *not* exist)
for d in tails:
#print "head = %s, d = %s: " % (head, d),
head = os.path.join (head, d)
if _path_created.get (head):
head = os.path.join(head, d)
if _path_created.get(head):
continue
if verbose:
......@@ -72,7 +72,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
if not dry_run:
try:
os.mkdir (head)
os.mkdir(head)
created_dirs.append(head)
except OSError, exc:
raise DistutilsFileError, \
......@@ -97,13 +97,13 @@ def create_tree (base_dir, files, mode=0777, verbose=0, dry_run=0):
# First get the list of directories to create
need_dir = {}
for file in files:
need_dir[os.path.join (base_dir, os.path.dirname (file))] = 1
need_dir[os.path.join(base_dir, os.path.dirname(file))] = 1
need_dirs = need_dir.keys()
need_dirs.sort()
# Now create them
for dir in need_dirs:
mkpath (dir, mode, verbose, dry_run)
mkpath(dir, mode, verbose, dry_run)
# create_tree ()
......@@ -136,11 +136,11 @@ def copy_tree (src, dst,
from distutils.file_util import copy_file
if not dry_run and not os.path.isdir (src):
if not dry_run and not os.path.isdir(src):
raise DistutilsFileError, \
"cannot copy tree '%s': not a directory" % src
try:
names = os.listdir (src)
names = os.listdir(src)
except os.error, (errno, errstr):
if dry_run:
names = []
......@@ -149,32 +149,32 @@ def copy_tree (src, dst,
"error listing files in '%s': %s" % (src, errstr)
if not dry_run:
mkpath (dst, verbose=verbose)
mkpath(dst, verbose=verbose)
outputs = []
for n in names:
src_name = os.path.join (src, n)
dst_name = os.path.join (dst, n)
src_name = os.path.join(src, n)
dst_name = os.path.join(dst, n)
if preserve_symlinks and os.path.islink (src_name):
link_dest = os.readlink (src_name)
if preserve_symlinks and os.path.islink(src_name):
link_dest = os.readlink(src_name)
if verbose:
print "linking %s -> %s" % (dst_name, link_dest)
if not dry_run:
os.symlink (link_dest, dst_name)
outputs.append (dst_name)
os.symlink(link_dest, dst_name)
outputs.append(dst_name)
elif os.path.isdir (src_name):
outputs.extend (
copy_tree (src_name, dst_name,
preserve_mode, preserve_times, preserve_symlinks,
update, verbose, dry_run))
elif os.path.isdir(src_name):
outputs.extend(
copy_tree(src_name, dst_name,
preserve_mode, preserve_times, preserve_symlinks,
update, verbose, dry_run))
else:
copy_file (src_name, dst_name,
preserve_mode, preserve_times,
update, None, verbose, dry_run)
outputs.append (dst_name)
copy_file(src_name, dst_name,
preserve_mode, preserve_times,
update, None, verbose, dry_run)
outputs.append(dst_name)
return outputs
......
This diff is collapsed.
......@@ -55,7 +55,7 @@ class FileList:
# -- Fallback warning/debug functions ------------------------------
def __warn (self, msg):
sys.stderr.write ("warning: %s\n" % msg)
sys.stderr.write("warning: %s\n" % msg)
def __debug_print (self, msg):
"""Print 'msg' to stdout if the global DEBUG (taken from the
......@@ -87,7 +87,7 @@ class FileList:
def remove_duplicates (self):
# 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]:
del self.files[i]
......@@ -95,21 +95,21 @@ class FileList:
# -- "File template" methods ---------------------------------------
def _parse_template_line (self, line):
words = string.split (line)
words = string.split(line)
action = words[0]
patterns = dir = dir_pattern = None
if action in ('include', 'exclude',
'global-include', 'global-exclude'):
if len (words) < 2:
if len(words) < 2:
raise DistutilsTemplateError, \
"'%s' expects <pattern1> <pattern2> ..." % action
patterns = map(convert_path, words[1:])
elif action in ('recursive-include', 'recursive-exclude'):
if len (words) < 3:
if len(words) < 3:
raise DistutilsTemplateError, \
"'%s' expects <dir> <pattern1> <pattern2> ..." % action
......@@ -117,7 +117,7 @@ class FileList:
patterns = map(convert_path, words[2:])
elif action in ('graft', 'prune'):
if len (words) != 2:
if len(words) != 2:
raise DistutilsTemplateError, \
"'%s' expects a single <dir_pattern>" % action
......@@ -146,13 +146,13 @@ class FileList:
if action == 'include':
self.debug_print("include " + string.join(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)
elif action == 'exclude':
self.debug_print("exclude " + string.join(patterns))
for pattern in patterns:
if not self.exclude_pattern (pattern, anchor=1):
if not self.exclude_pattern(pattern, anchor=1):
self.warn(
"no previously-included files found matching '%s'"%
pattern)
......@@ -160,15 +160,15 @@ class FileList:
elif action == 'global-include':
self.debug_print("global-include " + string.join(patterns))
for pattern in patterns:
if not self.include_pattern (pattern, anchor=0):
self.warn (("no files found matching '%s' " +
"anywhere in distribution") %
pattern)
if not self.include_pattern(pattern, anchor=0):
self.warn(("no files found matching '%s' " +
"anywhere in distribution") %
pattern)
elif action == 'global-exclude':
self.debug_print("global-exclude " + string.join(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' " +
"found anywhere in distribution") %
pattern)
......@@ -177,8 +177,8 @@ class FileList:
self.debug_print("recursive-include %s %s" %
(dir, string.join(patterns)))
for pattern in patterns:
if not self.include_pattern (pattern, prefix=dir):
self.warn (("no files found matching '%s' " +
if not self.include_pattern(pattern, prefix=dir):
self.warn(("no files found matching '%s' " +
"under directory '%s'") %
(pattern, dir))
......@@ -190,11 +190,11 @@ class FileList:
self.warn(("no previously-included files matching '%s' " +
"found under directory '%s'") %
(pattern, dir))
elif action == 'graft':
self.debug_print("graft " + dir_pattern)
if not self.include_pattern(None, prefix=dir_pattern):
self.warn ("no directories found matching '%s'" % dir_pattern)
self.warn("no directories found matching '%s'" % dir_pattern)
elif action == 'prune':
self.debug_print("prune " + dir_pattern)
......@@ -212,8 +212,7 @@ class FileList:
# -- Filtering/selection methods -----------------------------------
def include_pattern (self, pattern,
anchor=1, prefix=None, is_regex=0):
anchor=1, prefix=None, is_regex=0):
"""Select strings (presumably filenames) from 'self.files' that
match 'pattern', a Unix-style wildcard (glob) pattern. Patterns
are not quite the same as implemented by the 'fnmatch' module: '*'
......@@ -239,7 +238,7 @@ class FileList:
Return 1 if files are found.
"""
files_found = 0
pattern_re = translate_pattern (pattern, anchor, prefix, is_regex)
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
self.debug_print("include_pattern: applying regex r'%s'" %
pattern_re.pattern)
......@@ -248,9 +247,9 @@ class FileList:
self.findall()
for name in self.allfiles:
if pattern_re.search (name):
if pattern_re.search(name):
self.debug_print(" adding " + name)
self.files.append (name)
self.files.append(name)
files_found = 1
return files_found
......@@ -267,11 +266,11 @@ class FileList:
Return 1 if files are found.
"""
files_found = 0
pattern_re = translate_pattern (pattern, anchor, prefix, is_regex)
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
self.debug_print("exclude_pattern: applying regex r'%s'" %
pattern_re.pattern)
for i in range (len(self.files)-1, -1, -1):
if pattern_re.search (self.files[i]):
for i in range(len(self.files)-1, -1, -1):
if pattern_re.search(self.files[i]):
self.debug_print(" removing " + self.files[i])
del self.files[i]
files_found = 1
......@@ -299,11 +298,11 @@ def findall (dir = os.curdir):
while stack:
dir = pop()
names = os.listdir (dir)
names = os.listdir(dir)
for name in names:
if dir != os.curdir: # avoid the dreaded "./" syndrome
fullname = os.path.join (dir, name)
fullname = os.path.join(dir, name)
else:
fullname = name
......@@ -311,9 +310,9 @@ def findall (dir = os.curdir):
stat = os.stat(fullname)
mode = stat[ST_MODE]
if S_ISREG(mode):
list.append (fullname)
list.append(fullname)
elif S_ISDIR(mode) and not S_ISLNK(mode):
push (fullname)
push(fullname)
return list
......@@ -324,7 +323,7 @@ def glob_to_re (pattern):
that '*' does not match "special characters" (which are
platform-specific).
"""
pattern_re = fnmatch.translate (pattern)
pattern_re = fnmatch.translate(pattern)
# '?' and '*' in the glob pattern become '.' and '.*' in the RE, which
# IMHO is wrong -- '?' and '*' aren't supposed to match slash in Unix,
......@@ -333,7 +332,7 @@ def glob_to_re (pattern):
# character except the special characters.
# XXX currently the "special characters" are just slash -- i.e. this is
# Unix-only.
pattern_re = re.sub (r'(^|[^\\])\.', r'\1[^/]', pattern_re)
pattern_re = re.sub(r'(^|[^\\])\.', r'\1[^/]', pattern_re)
return pattern_re
# glob_to_re ()
......@@ -352,17 +351,17 @@ def translate_pattern (pattern, anchor=1, prefix=None, is_regex=0):
return pattern
if pattern:
pattern_re = glob_to_re (pattern)
pattern_re = glob_to_re(pattern)
else:
pattern_re = ''
if prefix is not None:
prefix_re = (glob_to_re (prefix))[0:-1] # ditch trailing $
pattern_re = "^" + os.path.join (prefix_re, ".*" + pattern_re)
prefix_re = (glob_to_re(prefix))[0:-1] # ditch trailing $
pattern_re = "^" + os.path.join(prefix_re, ".*" + pattern_re)
else: # no prefix -- respect anchor flag
if anchor:
pattern_re = "^" + pattern_re
return re.compile (pattern_re)
return re.compile(pattern_re)
# translate_pattern ()
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