Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
distutils.filelist.FileList Class Reference

List of all members.

Public Member Functions

def __init__
def set_allfiles
def findall
def debug_print
def append
def extend
def sort
def remove_duplicates
def process_template_line
def include_pattern
def exclude_pattern

Public Attributes

 allfiles
 files

Private Member Functions

def _parse_template_line

Detailed Description

A list of files built by on exploring the filesystem and filtered by
applying various patterns to what we find there.

Instance attributes:
  dir
    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)

Definition at line 13 of file filelist.py.


Constructor & Destructor Documentation

def distutils.filelist.FileList.__init__ (   self,
  warn = None,
  debug_print = None 
)

Definition at line 28 of file filelist.py.

00028 
00029     def __init__(self, warn=None, debug_print=None):
00030         # ignore argument to FileList, but keep them for backwards
00031         # compatibility
00032         self.allfiles = None
00033         self.files = []

Here is the caller graph for this function:


Member Function Documentation

def distutils.filelist.FileList._parse_template_line (   self,
  line 
) [private]

Definition at line 75 of file filelist.py.

00075 
00076     def _parse_template_line(self, line):
00077         words = line.split()
00078         action = words[0]
00079 
00080         patterns = dir = dir_pattern = None
00081 
00082         if action in ('include', 'exclude',
00083                       'global-include', 'global-exclude'):
00084             if len(words) < 2:
00085                 raise DistutilsTemplateError(
00086                       "'%s' expects <pattern1> <pattern2> ..." % action)
00087             patterns = [convert_path(w) for w in words[1:]]
00088         elif action in ('recursive-include', 'recursive-exclude'):
00089             if len(words) < 3:
00090                 raise DistutilsTemplateError(
00091                       "'%s' expects <dir> <pattern1> <pattern2> ..." % action)
00092             dir = convert_path(words[1])
00093             patterns = [convert_path(w) for w in words[2:]]
00094         elif action in ('graft', 'prune'):
00095             if len(words) != 2:
00096                 raise DistutilsTemplateError(
00097                       "'%s' expects a single <dir_pattern>" % action)
00098             dir_pattern = convert_path(words[1])
00099         else:
00100             raise DistutilsTemplateError("unknown action '%s'" % action)
00101 
00102         return (action, patterns, dir, dir_pattern)

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.filelist.FileList.append (   self,
  item 
)

Definition at line 50 of file filelist.py.

00050 
00051     def append(self, item):
00052         self.files.append(item)

Here is the caller graph for this function:

def distutils.filelist.FileList.debug_print (   self,
  msg 
)
Print 'msg' to stdout if the global DEBUG (taken from the
DISTUTILS_DEBUG environment variable) flag is true.

Definition at line 40 of file filelist.py.

00040 
00041     def debug_print(self, msg):
00042         """Print 'msg' to stdout if the global DEBUG (taken from the
00043         DISTUTILS_DEBUG environment variable) flag is true.
00044         """
00045         from distutils.debug import DEBUG
00046         if DEBUG:
00047             print(msg)

Here is the caller graph for this function:

def distutils.filelist.FileList.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 True if files are found, False otherwise.

Definition at line 222 of file filelist.py.

00222 
00223                          anchor=1, prefix=None, is_regex=0):
00224         """Remove strings (presumably filenames) from 'files' that match
00225         'pattern'.  Other parameters are the same as for
00226         'include_pattern()', above.
00227         The list 'self.files' is modified in place.
00228         Return True if files are found, False otherwise.
00229         """
00230         files_found = False
00231         pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
00232         self.debug_print("exclude_pattern: applying regex r'%s'" %
00233                          pattern_re.pattern)
00234         for i in range(len(self.files)-1, -1, -1):
00235             if pattern_re.search(self.files[i]):
00236                 self.debug_print(" removing " + self.files[i])
00237                 del self.files[i]
00238                 files_found = True
00239         return files_found
00240 
00241 
00242 # ----------------------------------------------------------------------
00243 # Utility functions

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.filelist.FileList.extend (   self,
  items 
)

Definition at line 53 of file filelist.py.

00053 
00054     def extend(self, items):
00055         self.files.extend(items)

def distutils.filelist.FileList.findall (   self,
  dir = os.curdir 
)

Definition at line 37 of file filelist.py.

00037 
00038     def findall(self, dir=os.curdir):
00039         self.allfiles = findall(dir)

Here is the caller graph for this function:

def distutils.filelist.FileList.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
DOS/Windows; and colon on Mac OS.

If 'anchor' is true (the default), then the pattern match is more
stringent: "*.py" will match "foo.py" but not "foo/bar.py".  If
'anchor' is false, both of these will match.

If 'prefix' is supplied, then only filenames starting with 'prefix'
(itself a pattern) and ending with 'pattern', with anything in between
them, will match.  'anchor' is ignored in this case.

If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and
'pattern' is assumed to be either a string containing a regex or a
regex object -- no translation is done, the regex is just compiled
and used as-is.

Selected strings will be added to self.files.

Return True if files are found, False otherwise.

Definition at line 179 of file filelist.py.

00179 
00180     def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
00181         """Select strings (presumably filenames) from 'self.files' that
00182         match 'pattern', a Unix-style wildcard (glob) pattern.  Patterns
00183         are not quite the same as implemented by the 'fnmatch' module: '*'
00184         and '?'  match non-special characters, where "special" is platform-
00185         dependent: slash on Unix; colon, slash, and backslash on
00186         DOS/Windows; and colon on Mac OS.
00187 
00188         If 'anchor' is true (the default), then the pattern match is more
00189         stringent: "*.py" will match "foo.py" but not "foo/bar.py".  If
00190         'anchor' is false, both of these will match.
00191 
00192         If 'prefix' is supplied, then only filenames starting with 'prefix'
00193         (itself a pattern) and ending with 'pattern', with anything in between
00194         them, will match.  'anchor' is ignored in this case.
00195 
00196         If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and
00197         'pattern' is assumed to be either a string containing a regex or a
00198         regex object -- no translation is done, the regex is just compiled
00199         and used as-is.
00200 
00201         Selected strings will be added to self.files.
00202 
00203         Return True if files are found, False otherwise.
00204         """
00205         files_found = False
00206         pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
00207         self.debug_print("include_pattern: applying regex r'%s'" %
00208                          pattern_re.pattern)
00209 
00210         # delayed loading of allfiles list
00211         if self.allfiles is None:
00212             self.findall()
00213 
00214         for name in self.allfiles:
00215             if pattern_re.search(name):
00216                 self.debug_print(" adding " + name)
00217                 self.files.append(name)
00218                 files_found = True
00219         return files_found
00220 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 103 of file filelist.py.

00103 
00104     def process_template_line(self, line):
00105         # Parse the line: split it up, make sure the right number of words
00106         # is there, and return the relevant words.  'action' is always
00107         # defined: it's the first word of the line.  Which of the other
00108         # three are defined depends on the action; it'll be either
00109         # patterns, (dir and patterns), or (dir_pattern).
00110         (action, patterns, dir, dir_pattern) = self._parse_template_line(line)
00111 
00112         # OK, now we know that the action is valid and we have the
00113         # right number of words on the line for that action -- so we
00114         # can proceed with minimal error-checking.
00115         if action == 'include':
00116             self.debug_print("include " + ' '.join(patterns))
00117             for pattern in patterns:
00118                 if not self.include_pattern(pattern, anchor=1):
00119                     log.warn("warning: no files found matching '%s'",
00120                              pattern)
00121 
00122         elif action == 'exclude':
00123             self.debug_print("exclude " + ' '.join(patterns))
00124             for pattern in patterns:
00125                 if not self.exclude_pattern(pattern, anchor=1):
00126                     log.warn(("warning: no previously-included files "
00127                               "found matching '%s'"), pattern)
00128 
00129         elif action == 'global-include':
00130             self.debug_print("global-include " + ' '.join(patterns))
00131             for pattern in patterns:
00132                 if not self.include_pattern(pattern, anchor=0):
00133                     log.warn(("warning: no files found matching '%s' "
00134                               "anywhere in distribution"), pattern)
00135 
00136         elif action == 'global-exclude':
00137             self.debug_print("global-exclude " + ' '.join(patterns))
00138             for pattern in patterns:
00139                 if not self.exclude_pattern(pattern, anchor=0):
00140                     log.warn(("warning: no previously-included files matching "
00141                               "'%s' found anywhere in distribution"),
00142                              pattern)
00143 
00144         elif action == 'recursive-include':
00145             self.debug_print("recursive-include %s %s" %
00146                              (dir, ' '.join(patterns)))
00147             for pattern in patterns:
00148                 if not self.include_pattern(pattern, prefix=dir):
00149                     log.warn(("warning: no files found matching '%s' "
00150                                 "under directory '%s'"),
00151                              pattern, dir)
00152 
00153         elif action == 'recursive-exclude':
00154             self.debug_print("recursive-exclude %s %s" %
00155                              (dir, ' '.join(patterns)))
00156             for pattern in patterns:
00157                 if not self.exclude_pattern(pattern, prefix=dir):
00158                     log.warn(("warning: no previously-included files matching "
00159                               "'%s' found under directory '%s'"),
00160                              pattern, dir)
00161 
00162         elif action == 'graft':
00163             self.debug_print("graft " + dir_pattern)
00164             if not self.include_pattern(None, prefix=dir_pattern):
00165                 log.warn("warning: no directories found matching '%s'",
00166                          dir_pattern)
00167 
00168         elif action == 'prune':
00169             self.debug_print("prune " + dir_pattern)
00170             if not self.exclude_pattern(None, prefix=dir_pattern):
00171                 log.warn(("no previously-included directories found "
00172                           "matching '%s'"), dir_pattern)
00173         else:
00174             raise DistutilsInternalError(
00175                   "this cannot happen: invalid action '%s'" % action)
00176 

Here is the call graph for this function:

Definition at line 66 of file filelist.py.

00066 
00067     def remove_duplicates(self):
00068         # Assumes list has been sorted!
00069         for i in range(len(self.files) - 1, 0, -1):
00070             if self.files[i] == self.files[i - 1]:
00071                 del self.files[i]
00072 

def distutils.filelist.FileList.set_allfiles (   self,
  allfiles 
)

Definition at line 34 of file filelist.py.

00034 
00035     def set_allfiles(self, allfiles):
00036         self.allfiles = allfiles

Definition at line 56 of file filelist.py.

00056 
00057     def sort(self):
00058         # Not a strict lexical sort!
00059         sortable_files = sorted(map(os.path.split, self.files))
00060         self.files = []
00061         for sort_tuple in sortable_files:
00062             self.files.append(os.path.join(*sort_tuple))
00063 

Here is the call graph for this function:


Member Data Documentation

Definition at line 31 of file filelist.py.

Definition at line 32 of file filelist.py.


The documentation for this class was generated from the following file: