summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2003-04-27 03:52:45 (GMT)
committerSteven Knight <knight@baldmt.com>2003-04-27 03:52:45 (GMT)
commit2f2de15b1c371600d955451cd479b58bab78a517 (patch)
tree918c1124f7c30f513e842e163722d308614e510c /bin
parent98792e70711bb39b7862e4427c09787aab691631 (diff)
downloadSCons-2f2de15b1c371600d955451cd479b58bab78a517.zip
SCons-2f2de15b1c371600d955451cd479b58bab78a517.tar.gz
SCons-2f2de15b1c371600d955451cd479b58bab78a517.tar.bz2
Add a script to count our source-vs.-test lines of code.
Diffstat (limited to 'bin')
-rw-r--r--bin/linecount62
1 files changed, 62 insertions, 0 deletions
diff --git a/bin/linecount b/bin/linecount
new file mode 100644
index 0000000..6034208
--- /dev/null
+++ b/bin/linecount
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+#
+# Count statistics about SCons test and source files. This must be run
+# against a fully-populated tree (for example, one that's been freshly
+# checked out).
+#
+# A test file is anything under the src/ directory that ends in
+# 'Tests.py', or anything under the test/ directory that ends in '.py'.
+#
+# A source file is anything under the src/engine/ or src/script/
+# directories that ends in '.py' but does NOT end in 'Tests.py'. (We
+# should probably ignore the stuff in src/engine/SCons/Optik, since it
+# doesn't originate with SCons, but what the hell.)
+#
+# We report the number of tests and sources, the total number of lines
+# in each category, the number of non-blank lines, and the number of
+# non-comment lines. The last figure (non-comment) lines is the most
+# interesting one for most purposes.
+#
+
+import os.path
+import string
+
+tests = []
+sources = []
+
+def t(arg, dirname, names):
+ names = filter(lambda n: n[-8:] == 'Tests.py', names)
+ arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names))
+os.path.walk('src', t, tests)
+
+def p(arg, dirname, names):
+ names = filter(lambda n: n[-3:] == '.py', names)
+ arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names))
+os.path.walk('test', p, tests)
+
+def s(arg, dirname, names):
+ names = filter(lambda n: n[-3:] == '.py' and n[-8:] != 'Tests.py', names)
+ arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names))
+os.path.walk('src/engine', s, sources)
+os.path.walk('src/script', s, sources)
+
+def gather(files):
+ lines = []
+ for file in files:
+ lines.extend(open(file).readlines())
+ return lines
+
+tlines = map(string.lstrip, gather(tests))
+slines = map(string.lstrip, gather(sources))
+
+nbtl = filter(lambda x: x != '', tlines)
+nbsl = filter(lambda x: x != '', slines)
+
+nctl = filter(lambda x: x[0] != '#', nbtl)
+ncsl = filter(lambda x: x[0] != '#', nbsl)
+
+fmt = "%-8s %12s %12s %12s %12s"
+
+print fmt % ('', 'files', 'lines', 'non-blank', 'non-comment')
+print fmt % ('tests:', len(tests), len(tlines), len(nbtl), len(nctl))
+print fmt % ('sources:', len(sources), len(slines), len(nbsl), len(ncsl))