Refactory bin/* utilities to use os.walk() instead of os.path.walk().
[scons.git] / bin / linecount.py
index 33f9f73714d971fb30f337dec6fb42209d1f284b..b433284a6ba1f00d37c1f3280edd733a8ec0f9d8 100644 (file)
 # non-comment lines.  The last figure (non-comment) lines is the most
 # interesting one for most purposes.
 #
+from __future__ import generators  ### KEEP FOR COMPATIBILITY FIXERS
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os.path
-import string
 
 fmt = "%-16s  %5s  %7s  %9s  %11s  %11s"
 
@@ -43,8 +43,12 @@ class Collection(object):
     return self.pred(fname)
   def __len__(self):
     return len(self.files)
-  def extend(self, files):
-    self.files.extend(files)
+  def collect(self, directory):
+    for dirpath, dirnames, filenames in os.walk(directory):
+      try: dirnames.remove('.svn')
+      except ValueError: pass
+      self.files.extend([ os.path.join(dirpath, f)
+                          for f in filenames if self.pred(f) ])
   def lines(self):
     try:
       return self._lines
@@ -82,17 +86,11 @@ src_test_tests = Collection('src/ test_*.py', pred=is_test_)
 test_tests = Collection('test/ tests', pred=is_python)
 sources = Collection('sources', pred=is_source)
 
-def t(arg, dirname, names):
-    try: names.remove('.svn')
-    except ValueError: pass
-    names = filter(arg, names)
-    arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names))
-
-os.path.walk('src', t, src_Tests_py_tests)
-os.path.walk('src', t, src_test_tests)
-os.path.walk('test', t, test_tests)
-os.path.walk('src/engine', t, sources)
-os.path.walk('src/script', t, sources)
+src_Tests_py_tests.collect('src')
+src_test_tests.collect('src')
+test_tests.collect('test')
+sources.collect('src/engine')
+sources.collect('src/script')
 
 src_tests = Collection('src/ tests', src_Tests_py_tests.files
                                      + src_test_tests.files)