diff options
author | Steven Knight <knight@baldmt.com> | 2010-04-16 13:40:49 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2010-04-16 13:40:49 (GMT) |
commit | ded0f52f11f5c97959ee8070a2687ecb14e69e3f (patch) | |
tree | 62ceb50351ad2bb0343b1f12b291449f8203dfba /bin/linecount.py | |
parent | c06950cad4c02ba6b759c1cbd65cfb52ab6868c3 (diff) | |
download | SCons-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/linecount.py')
-rw-r--r-- | bin/linecount.py | 24 |
1 files changed, 11 insertions, 13 deletions
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) |