From 58991d38806eb6638a0bddd75f53e00d45ba54af Mon Sep 17 00:00:00 2001 From: stevenknight Date: Fri, 16 Apr 2010 13:40:49 +0000 Subject: [PATCH] Refactory bin/* utilities to use os.walk() instead of os.path.walk(). git-svn-id: http://scons.tigris.org/svn/scons/trunk@4788 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- bin/import-test.py | 10 ++++------ bin/linecount.py | 24 +++++++++++------------- bin/scons-doc.py | 9 +++------ 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/bin/import-test.py b/bin/import-test.py index 69e6cc7d..8ed5399d 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 715d2072..b433284a 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 f7a3a232..7e49cbea 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()) -- 2.26.2