Refactory bin/* utilities to use os.walk() instead of os.path.walk().
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 16 Apr 2010 13:40:49 +0000 (13:40 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 16 Apr 2010 13:40:49 +0000 (13:40 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@4788 fdb21ef1-2011-0410-befe-b5e4ea1792b1

bin/import-test.py
bin/linecount.py
bin/scons-doc.py

index 69e6cc7de6d8fca3349eff60166418dee0be8358..8ed5399d81c32f66da3d4dbc27f4719679ac1b2e 100644 (file)
@@ -57,11 +57,6 @@ def lookup(dirname):
     node = t.entries[dirs[-1]] = Dir(dirs)
     return node
 
-def make_nodes(arg, dirname, fnames):
-    dir = lookup(dirname)
-    for f in fnames:
-        dir.entries[f] = None
-
 def collect_dirs(l, dir):
     if dir.path:
         l.append(dir.path)
@@ -85,7 +80,10 @@ def print_files(dir):
             print_files(d)
     dir.call_for_each_entry(recurse)
 
-os.path.walk(directory, make_nodes, None)
+for dirpath, dirnames, filenames in os.walk(directory):
+    dir = lookup(dirpath)
+    for f in fnames:
+        dir.entries[f] = None
 
 subdir_list = []
 collect_dirs(subdir_list, Top)
index 715d20720c98cc6b546faabaf2890508149525a2..b433284a6ba1f00d37c1f3280edd733a8ec0f9d8 100644 (file)
@@ -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 = list(filter(arg, names))
-    arg.extend([os.path.join(dirname, n) for n in 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)
index f7a3a232885552f62a66fcd52e7c6cfd209e4862..7e49cbea14a27066234806bb8d737c33c4425517 100644 (file)
@@ -322,16 +322,13 @@ def JavaHCom(target, source, env):
     for t, s in zip(tlist, slist):
         open(t, "wb").write(open(s, "rb").read())
 
-def find_class_files(arg, dirname, names):
-    class_files = filter(lambda n: n[-6:] == '.class', names)
-    paths = map(lambda n: os.path.join(dirname, n), class_files)
-    arg.extend(paths)
-
 def JarCom(target, source, env):
     target = str(target[0])
     class_files = []
     for src in map(str, source):
-        os.path.walk(src, find_class_files, class_files)
+        for dirpath, dirnames, filenames in os.walk(src):
+            class_files.extend([ os.path.join(dirpath, f)
+                                 for f in filenames if f.endswith('.class') ])
     f = open(target, "wb")
     for cf in class_files:
         f.write(open(cf, "rb").read())