mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Added class docstring and ditched inappropriate class attrs.
Indentation/whitspace fixes.
This commit is contained in:
parent
adc1172064
commit
c98927a059
1 changed files with 120 additions and 117 deletions
|
@ -19,15 +19,19 @@ from distutils.util import convert_path
|
||||||
|
|
||||||
class FileList:
|
class FileList:
|
||||||
|
|
||||||
files = None # reference to files list to mainpulate
|
"""A list of files built by on exploring the filesystem and filtered by
|
||||||
allfiles = None # list of all files, if None will be filled
|
applying various patterns to what we find there.
|
||||||
# at first use from directory self.dir
|
|
||||||
dir = None # directory from which files will be taken
|
|
||||||
# to fill self.allfiles if it was not set otherwise
|
|
||||||
|
|
||||||
# next both functions (callable objects) can be set by the user
|
Instance attributes:
|
||||||
# warn: warning function
|
dir
|
||||||
# debug_print: debug function
|
directory from which files will be taken -- only used if
|
||||||
|
'allfiles' not supplied to constructor
|
||||||
|
files
|
||||||
|
list of filenames currently being built/filtered/manipulated
|
||||||
|
allfiles
|
||||||
|
complete list of files under consideration (ie. without any
|
||||||
|
filtering applied)
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
files=[],
|
files=[],
|
||||||
|
@ -42,13 +46,14 @@ class FileList:
|
||||||
self.debug_print = debug_print
|
self.debug_print = debug_print
|
||||||
self.files = files
|
self.files = files
|
||||||
self.dir = dir
|
self.dir = dir
|
||||||
|
|
||||||
|
# if None, 'allfiles' will be filled when used for first time
|
||||||
self.allfiles = allfiles
|
self.allfiles = allfiles
|
||||||
# if None, it will be filled, when used for first time
|
|
||||||
|
|
||||||
|
|
||||||
# standard warning and debug functions, if no other given
|
# standard warning and debug functions, if no other given
|
||||||
def __warn (self, msg):
|
def __warn (self, msg):
|
||||||
sys.stderr.write ("warning: template: %s\n" % msg)
|
sys.stderr.write ("warning: %s\n" % msg)
|
||||||
|
|
||||||
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
|
||||||
|
@ -59,130 +64,128 @@ class FileList:
|
||||||
print msg
|
print msg
|
||||||
|
|
||||||
|
|
||||||
def process_line(self, line):
|
def process_line (self, line):
|
||||||
|
|
||||||
words = string.split (line)
|
words = string.split (line)
|
||||||
action = words[0]
|
action = words[0]
|
||||||
|
|
||||||
# First, check that the right number of words are present
|
# First, check that the right number of words are present
|
||||||
# for the given action (which is the first word)
|
# for the given action (which is the first word)
|
||||||
if action in ('include','exclude',
|
if action in ('include','exclude',
|
||||||
'global-include','global-exclude'):
|
'global-include','global-exclude'):
|
||||||
if len (words) < 2:
|
if len (words) < 2:
|
||||||
self.warn \
|
self.warn \
|
||||||
("invalid template line: " +
|
("invalid template line: " +
|
||||||
"'%s' expects <pattern1> <pattern2> ..." %
|
"'%s' expects <pattern1> <pattern2> ..." %
|
||||||
action)
|
action)
|
||||||
return
|
|
||||||
|
|
||||||
pattern_list = map(convert_path, words[1:])
|
|
||||||
|
|
||||||
elif action in ('recursive-include','recursive-exclude'):
|
|
||||||
if len (words) < 3:
|
|
||||||
self.warn \
|
|
||||||
("invalid template line: " +
|
|
||||||
"'%s' expects <dir> <pattern1> <pattern2> ..." %
|
|
||||||
action)
|
|
||||||
return
|
|
||||||
|
|
||||||
dir = convert_path(words[1])
|
|
||||||
pattern_list = map (convert_path, words[2:])
|
|
||||||
|
|
||||||
elif action in ('graft','prune'):
|
|
||||||
if len (words) != 2:
|
|
||||||
self.warn \
|
|
||||||
("invalid template line: " +
|
|
||||||
"'%s' expects a single <dir_pattern>" %
|
|
||||||
action)
|
|
||||||
return
|
|
||||||
|
|
||||||
dir_pattern = convert_path (words[1])
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.warn ("invalid template line: " +
|
|
||||||
"unknown action '%s'" % action)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# OK, now we know that the action is valid and we have the
|
pattern_list = map(convert_path, words[1:])
|
||||||
# right number of words on the line for that action -- so we
|
|
||||||
# can proceed with minimal error-checking. Also, we have
|
|
||||||
# defined either (pattern), (dir and pattern), or
|
|
||||||
# (dir_pattern) -- so we don't have to spend any time
|
|
||||||
# digging stuff up out of 'words'.
|
|
||||||
|
|
||||||
if action == 'include':
|
elif action in ('recursive-include','recursive-exclude'):
|
||||||
self.debug_print("include " + string.join(pattern_list))
|
if len (words) < 3:
|
||||||
for pattern in pattern_list:
|
self.warn \
|
||||||
if not self.select_pattern (pattern, anchor=1):
|
("invalid template line: " +
|
||||||
self.warn ("no files found matching '%s'" %
|
"'%s' expects <dir> <pattern1> <pattern2> ..." %
|
||||||
pattern)
|
action)
|
||||||
|
return
|
||||||
|
|
||||||
elif action == 'exclude':
|
dir = convert_path(words[1])
|
||||||
self.debug_print("exclude " + string.join(pattern_list))
|
pattern_list = map (convert_path, words[2:])
|
||||||
for pattern in pattern_list:
|
|
||||||
if not self.exclude_pattern (pattern, anchor=1):
|
|
||||||
self.warn (
|
|
||||||
"no previously-included files found matching '%s'"%
|
|
||||||
pattern)
|
|
||||||
|
|
||||||
elif action == 'global-include':
|
elif action in ('graft','prune'):
|
||||||
self.debug_print("global-include " + string.join(pattern_list))
|
if len (words) != 2:
|
||||||
for pattern in pattern_list:
|
self.warn \
|
||||||
if not self.select_pattern (pattern, anchor=0):
|
("invalid template line: " +
|
||||||
self.warn (("no files found matching '%s' " +
|
"'%s' expects a single <dir_pattern>" %
|
||||||
"anywhere in distribution") %
|
action)
|
||||||
pattern)
|
return
|
||||||
|
|
||||||
elif action == 'global-exclude':
|
dir_pattern = convert_path (words[1])
|
||||||
self.debug_print("global-exclude " + string.join(pattern_list))
|
|
||||||
for pattern in pattern_list:
|
|
||||||
if not self.exclude_pattern (pattern, anchor=0):
|
|
||||||
self.warn \
|
|
||||||
(("no previously-included files matching '%s' " +
|
|
||||||
"found anywhere in distribution") %
|
|
||||||
pattern)
|
|
||||||
|
|
||||||
elif action == 'recursive-include':
|
else:
|
||||||
self.debug_print("recursive-include %s %s" %
|
self.warn ("invalid template line: " +
|
||||||
(dir, string.join(pattern_list)))
|
"unknown action '%s'" % action)
|
||||||
for pattern in pattern_list:
|
return
|
||||||
if not self.select_pattern (pattern, prefix=dir):
|
|
||||||
self.warn (("no files found matching '%s' " +
|
|
||||||
"under directory '%s'") %
|
|
||||||
(pattern, dir))
|
|
||||||
|
|
||||||
elif action == 'recursive-exclude':
|
# OK, now we know that the action is valid and we have the
|
||||||
self.debug_print("recursive-exclude %s %s" %
|
# right number of words on the line for that action -- so we
|
||||||
(dir, string.join(pattern_list)))
|
# can proceed with minimal error-checking. Also, we have
|
||||||
for pattern in pattern_list:
|
# defined either (pattern), (dir and pattern), or
|
||||||
if not self.exclude_pattern(pattern, prefix=dir):
|
# (dir_pattern) -- so we don't have to spend any time
|
||||||
self.warn \
|
# digging stuff up out of 'words'.
|
||||||
(("no previously-included files matching '%s' " +
|
|
||||||
"found under directory '%s'") %
|
|
||||||
(pattern, dir))
|
|
||||||
|
|
||||||
elif action == 'graft':
|
if action == 'include':
|
||||||
self.debug_print("graft " + dir_pattern)
|
self.debug_print("include " + string.join(pattern_list))
|
||||||
if not self.select_pattern(None, prefix=dir_pattern):
|
for pattern in pattern_list:
|
||||||
self.warn ("no directories found matching '%s'" %
|
if not self.select_pattern (pattern, anchor=1):
|
||||||
dir_pattern)
|
self.warn ("no files found matching '%s'" %
|
||||||
|
pattern)
|
||||||
|
|
||||||
elif action == 'prune':
|
elif action == 'exclude':
|
||||||
self.debug_print("prune " + dir_pattern)
|
self.debug_print("exclude " + string.join(pattern_list))
|
||||||
if not self.exclude_pattern(None, prefix=dir_pattern):
|
for pattern in pattern_list:
|
||||||
|
if not self.exclude_pattern (pattern, anchor=1):
|
||||||
|
self.warn (
|
||||||
|
"no previously-included files found matching '%s'"%
|
||||||
|
pattern)
|
||||||
|
|
||||||
|
elif action == 'global-include':
|
||||||
|
self.debug_print("global-include " + string.join(pattern_list))
|
||||||
|
for pattern in pattern_list:
|
||||||
|
if not self.select_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(pattern_list))
|
||||||
|
for pattern in pattern_list:
|
||||||
|
if not self.exclude_pattern (pattern, anchor=0):
|
||||||
self.warn \
|
self.warn \
|
||||||
(("no previously-included directories found " +
|
(("no previously-included files matching '%s' " +
|
||||||
"matching '%s'") %
|
"found anywhere in distribution") %
|
||||||
dir_pattern)
|
pattern)
|
||||||
else:
|
|
||||||
raise RuntimeError, \
|
elif action == 'recursive-include':
|
||||||
"this cannot happen: invalid action '%s'" % action
|
self.debug_print("recursive-include %s %s" %
|
||||||
|
(dir, string.join(pattern_list)))
|
||||||
|
for pattern in pattern_list:
|
||||||
|
if not self.select_pattern (pattern, prefix=dir):
|
||||||
|
self.warn (("no files found matching '%s' " +
|
||||||
|
"under directory '%s'") %
|
||||||
|
(pattern, dir))
|
||||||
|
|
||||||
|
elif action == 'recursive-exclude':
|
||||||
|
self.debug_print("recursive-exclude %s %s" %
|
||||||
|
(dir, string.join(pattern_list)))
|
||||||
|
for pattern in pattern_list:
|
||||||
|
if not self.exclude_pattern(pattern, prefix=dir):
|
||||||
|
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.select_pattern(None, prefix=dir_pattern):
|
||||||
|
self.warn ("no directories found matching '%s'" %
|
||||||
|
dir_pattern)
|
||||||
|
|
||||||
|
elif action == 'prune':
|
||||||
|
self.debug_print("prune " + dir_pattern)
|
||||||
|
if not self.exclude_pattern(None, prefix=dir_pattern):
|
||||||
|
self.warn \
|
||||||
|
(("no previously-included directories found " +
|
||||||
|
"matching '%s'") %
|
||||||
|
dir_pattern)
|
||||||
|
else:
|
||||||
|
raise RuntimeError, \
|
||||||
|
"this cannot happen: invalid action '%s'" % action
|
||||||
|
|
||||||
# process_line ()
|
# process_line ()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def select_pattern (self, pattern,
|
def select_pattern (self, pattern,
|
||||||
anchor=1, prefix=None, is_regex=0):
|
anchor=1, prefix=None, is_regex=0):
|
||||||
"""Select strings (presumably filenames) from 'files' that match
|
"""Select strings (presumably filenames) from 'files' that match
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue