[Python-checkins] CVS: distutils/distutils filelist.py,1.6,1.7

Greg Ward python-dev@python.org
2000年7月29日 18:45:45 -0700


Update of /cvsroot/python/distutils/distutils
In directory slayer.i.sourceforge.net:/tmp/cvs-serv27616
Modified Files:
	filelist.py 
Log Message:
Added list-like methods: 'append()', 'extend()', 'sort()'.
Added 'remove_duplicates()'.
Simplified constructor: no longer take 'files' or 'allfiles' as args,
 and no longer have 'dir' attribute at all.
Added 'set_allfiles()' and 'findall()' so the client does have a
 way to set the list of all files.
Changed 'include_pattern()' to use the 'findall()' method instead of
 the external function. (Of course, the method is just a trivial
 wrapper around the function.)
Index: filelist.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/filelist.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** filelist.py	2000年07月30日 01:04:22	1.6
--- filelist.py	2000年07月30日 01:45:42	1.7
***************
*** 36,57 ****
 
 def __init__(self, 
- files=[], 
- dir=os.curdir, 
- allfiles=None, 
 warn=None, 
 debug_print=None):
! # use standard warning and debug functions, if no other given
! if warn is None: warn = self.__warn 
! if debug_print is None: debug_print = self.__debug_print
! self.warn = warn
! self.debug_print = debug_print
! self.files = files
! self.dir = dir
 
! # if None, 'allfiles' will be filled when used for first time
! self.allfiles = allfiles 
 
 
! # standard warning and debug functions, if no other given
 def __warn (self, msg):
 sys.stderr.write ("warning: %s\n" % msg)
--- 36,58 ----
 
 def __init__(self, 
 warn=None, 
 debug_print=None):
! # use standard warning and debug functions if no other given
! self.warn = warn or self.__warn
! self.debug_print = debug_print or self.__debug_print
 
! self.allfiles = None
! self.files = []
 
 
! def set_allfiles (self, allfiles):
! self.allfiles = allfiles
! 
! def findall (self, dir=os.curdir):
! self.allfiles = findall(dir)
! 
! 
! # -- Fallback warning/debug functions ------------------------------
! 
 def __warn (self, msg):
 sys.stderr.write ("warning: %s\n" % msg)
***************
*** 65,68 ****
--- 66,97 ----
 print msg
 
+ 
+ # -- List-like methods ---------------------------------------------
+ 
+ def append (self, item):
+ self.files.append(item)
+ 
+ def extend (self, items):
+ self.files.extend(items)
+ 
+ def sort (self):
+ # Not a strict lexical sort!
+ sortable_files = map(os.path.split, self.files)
+ sortable_files.sort()
+ self.files = []
+ for sort_tuple in sortable_files:
+ self.files.append(apply(os.path.join, sort_tuple))
+ 
+ 
+ # -- Other miscellaneous utility methods ---------------------------
+ 
+ def remove_duplicates (self):
+ # Assumes list has been sorted!
+ for i in range (len(self.files)-1, 0, -1):
+ if self.files[i] == self.files[i-1]:
+ del self.files[i]
+ 
+ 
+ # -- "File template" methods ---------------------------------------
 
 def _parse_template_line (self, line):
***************
*** 181,184 ****
--- 210,215 ----
 
 
+ # -- Filtering/selection methods -----------------------------------
+ 
 def include_pattern (self, pattern,
 anchor=1, prefix=None, is_regex=0):
***************
*** 214,218 ****
 
 # delayed loading of allfiles list
! if self.allfiles is None: self.allfiles = findall (self.dir)
 
 for name in self.allfiles:
--- 245,250 ----
 
 # delayed loading of allfiles list
! if self.allfiles is None:
! self.findall()
 
 for name in self.allfiles:

AltStyle によって変換されたページ (->オリジナル) /