aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/distutils/filelist.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils/filelist.py')
-rw-r--r--Lib/distutils/filelist.py93
1 files changed, 39 insertions, 54 deletions
diff --git a/Lib/distutils/filelist.py b/Lib/distutils/filelist.py
index 2f1c457ea0b..db3f7a96802 100644
--- a/Lib/distutils/filelist.py
+++ b/Lib/distutils/filelist.py
@@ -4,8 +4,6 @@ Provides the FileList class, used for poking about the filesystem
and building lists of files.
"""
-__revision__ = "$Id$"
-
import os, re
import fnmatch
from distutils.util import convert_path
@@ -45,7 +43,7 @@ class FileList:
"""
from distutils.debug import DEBUG
if DEBUG:
- print msg
+ print(msg)
# -- List-like methods ---------------------------------------------
@@ -57,8 +55,7 @@ class FileList:
def sort(self):
# Not a strict lexical sort!
- sortable_files = map(os.path.split, self.files)
- sortable_files.sort()
+ sortable_files = sorted(map(os.path.split, self.files))
self.files = []
for sort_tuple in sortable_files:
self.files.append(os.path.join(*sort_tuple))
@@ -84,28 +81,22 @@ class FileList:
if action in ('include', 'exclude',
'global-include', 'global-exclude'):
if len(words) < 2:
- raise DistutilsTemplateError, \
- "'%s' expects <pattern1> <pattern2> ..." % action
-
- patterns = map(convert_path, words[1:])
-
+ raise DistutilsTemplateError(
+ "'%s' expects <pattern1> <pattern2> ..." % action)
+ patterns = [convert_path(w) for w in words[1:]]
elif action in ('recursive-include', 'recursive-exclude'):
if len(words) < 3:
- raise DistutilsTemplateError, \
- "'%s' expects <dir> <pattern1> <pattern2> ..." % action
-
+ raise DistutilsTemplateError(
+ "'%s' expects <dir> <pattern1> <pattern2> ..." % action)
dir = convert_path(words[1])
- patterns = map(convert_path, words[2:])
-
+ patterns = [convert_path(w) for w in words[2:]]
elif action in ('graft', 'prune'):
if len(words) != 2:
- raise DistutilsTemplateError, \
- "'%s' expects a single <dir_pattern>" % action
-
+ raise DistutilsTemplateError(
+ "'%s' expects a single <dir_pattern>" % action)
dir_pattern = convert_path(words[1])
-
else:
- raise DistutilsTemplateError, "unknown action '%s'" % action
+ raise DistutilsTemplateError("unknown action '%s'" % action)
return (action, patterns, dir, dir_pattern)
@@ -115,7 +106,7 @@ class FileList:
# defined: it's the first word of the line. Which of the other
# three are defined depends on the action; it'll be either
# patterns, (dir and patterns), or (dir_pattern).
- action, patterns, dir, dir_pattern = self._parse_template_line(line)
+ (action, patterns, dir, dir_pattern) = self._parse_template_line(line)
# OK, now we know that the action is valid and we have the
# right number of words on the line for that action -- so we
@@ -138,7 +129,7 @@ class FileList:
self.debug_print("global-include " + ' '.join(patterns))
for pattern in patterns:
if not self.include_pattern(pattern, anchor=0):
- log.warn(("warning: no files found matching '%s' " +
+ log.warn(("warning: no files found matching '%s' "
"anywhere in distribution"), pattern)
elif action == 'global-exclude':
@@ -154,7 +145,7 @@ class FileList:
(dir, ' '.join(patterns)))
for pattern in patterns:
if not self.include_pattern(pattern, prefix=dir):
- log.warn(("warning: no files found matching '%s' " +
+ log.warn(("warning: no files found matching '%s' "
"under directory '%s'"),
pattern, dir)
@@ -176,21 +167,21 @@ class FileList:
elif action == 'prune':
self.debug_print("prune " + dir_pattern)
if not self.exclude_pattern(None, prefix=dir_pattern):
- log.warn(("no previously-included directories found " +
+ log.warn(("no previously-included directories found "
"matching '%s'"), dir_pattern)
else:
- raise DistutilsInternalError, \
- "this cannot happen: invalid action '%s'" % action
+ raise DistutilsInternalError(
+ "this cannot happen: invalid action '%s'" % action)
+
# -- Filtering/selection methods -----------------------------------
def include_pattern(self, pattern, 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: '*' and '?' match non-special characters, where "special"
- is platform-dependent: slash on Unix; colon, slash, and backslash on
+ match 'pattern', a Unix-style wildcard (glob) pattern. Patterns
+ are not quite the same as implemented by the 'fnmatch' module: '*'
+ and '?' match non-special characters, where "special" is platform-
+ dependent: slash on Unix; colon, slash, and backslash on
DOS/Windows; and colon on Mac OS.
If 'anchor' is true (the default), then the pattern match is more
@@ -208,10 +199,10 @@ class FileList:
Selected strings will be added to self.files.
- Return 1 if files are found.
+ Return True if files are found, False otherwise.
"""
# XXX docstring lying about what the special chars are?
- files_found = 0
+ files_found = False
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
self.debug_print("include_pattern: applying regex r'%s'" %
pattern_re.pattern)
@@ -224,20 +215,19 @@ class FileList:
if pattern_re.search(name):
self.debug_print(" adding " + name)
self.files.append(name)
- files_found = 1
-
+ files_found = True
return files_found
- def exclude_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
+ def exclude_pattern (self, pattern,
+ anchor=1, prefix=None, is_regex=0):
"""Remove strings (presumably filenames) from 'files' that match
- 'pattern'.
-
- Other parameters are the same as for 'include_pattern()', above.
- The list 'self.files' is modified in place. Return 1 if files are
- found.
+ 'pattern'. Other parameters are the same as for
+ 'include_pattern()', above.
+ The list 'self.files' is modified in place.
+ Return True if files are found, False otherwise.
"""
- files_found = 0
+ files_found = False
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
self.debug_print("exclude_pattern: applying regex r'%s'" %
pattern_re.pattern)
@@ -245,15 +235,14 @@ class FileList:
if pattern_re.search(self.files[i]):
self.debug_print(" removing " + self.files[i])
del self.files[i]
- files_found = 1
-
+ files_found = True
return files_found
# ----------------------------------------------------------------------
# Utility functions
-def findall(dir = os.curdir):
+def findall(dir=os.curdir):
"""Find all files under 'dir' and return the list of full filenames
(relative to 'dir').
"""
@@ -281,16 +270,14 @@ def findall(dir = os.curdir):
list.append(fullname)
elif S_ISDIR(mode) and not S_ISLNK(mode):
push(fullname)
-
return list
def glob_to_re(pattern):
- """Translate a shell-like glob pattern to a regular expression.
-
- Return a string containing the regex. Differs from
- 'fnmatch.translate()' in that '*' does not match "special characters"
- (which are platform-specific).
+ """Translate a shell-like glob pattern to a regular expression; return
+ a string containing the regex. Differs from 'fnmatch.translate()' in
+ that '*' does not match "special characters" (which are
+ platform-specific).
"""
pattern_re = fnmatch.translate(pattern)
@@ -311,9 +298,7 @@ def glob_to_re(pattern):
def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
"""Translate a shell-like wildcard pattern to a compiled regular
- expression.
-
- Return the compiled regex. If 'is_regex' true,
+ expression. Return the compiled regex. If 'is_regex' true,
then 'pattern' is directly compiled to a regex (if it's a string)
or just returned as-is (assumes it's a regex object).
"""