summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2010-04-16 13:40:49 (GMT)
committerSteven Knight <knight@baldmt.com>2010-04-16 13:40:49 (GMT)
commitded0f52f11f5c97959ee8070a2687ecb14e69e3f (patch)
tree62ceb50351ad2bb0343b1f12b291449f8203dfba /bin
parentc06950cad4c02ba6b759c1cbd65cfb52ab6868c3 (diff)
downloadSCons-ded0f52f11f5c97959ee8070a2687ecb14e69e3f.zip
SCons-ded0f52f11f5c97959ee8070a2687ecb14e69e3f.tar.gz
SCons-ded0f52f11f5c97959ee8070a2687ecb14e69e3f.tar.bz2
Refactory bin/* utilities to use os.walk() instead of os.path.walk().
Diffstat (limited to 'bin')
-rw-r--r--bin/import-test.py10
-rw-r--r--bin/linecount.py24
-rw-r--r--bin/scons-doc.py9
3 files changed, 18 insertions, 25 deletions
diff --git a/bin/import-test.py b/bin/import-test.py
index 69e6cc7..8ed5399 100644
--- a/bin/import-test.py
+++ b/bin/import-test.py
@@ -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)
diff --git a/bin/linecount.py b/bin/linecount.py
index 715d207..b433284 100644
--- a/bin/linecount.py
+++ b/bin/linecount.py
@@ -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)
diff --git a/bin/scons-doc.py b/bin/scons-doc.py
index f7a3a23..7e49cbe 100644
--- a/bin/scons-doc.py
+++ b/bin/scons-doc.py
@@ -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())