[py-svn] r36509 - in py/dist/py: bin misc/cmdline

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Jan 11 16:58:56 CET 2007


Author: cfbolz
Date: Thu Jan 11 16:58:55 2007
New Revision: 36509

Modified:
   py/dist/py/bin/py.countloc
   py/dist/py/misc/cmdline/countloc.py
Log:
use optparse in py.countloc for extensibility and --help purposes. add a nice
--help string.


Modified: py/dist/py/bin/py.countloc
==============================================================================
--- py/dist/py/bin/py.countloc	(original)
+++ py/dist/py/bin/py.countloc	Thu Jan 11 16:58:55 2007
@@ -3,6 +3,21 @@
 # hands on script to compute the non-empty Lines of Code 
 # for tests and non-test code 
 
+"""\
+py.countloc [PATHS]
+
+Count (non-empty) lines of python code and number of python files recursively
+starting from a list of paths given on the command line (starting from the
+current working directory). Distinguish between test files and normal ones and
+report them separately.
+"""
 from _findpy import py 
+import py
+from py.compat import optparse
 from py.__.misc.cmdline.countloc import countloc 
-countloc()
+
+parser = optparse.OptionParser(usage=__doc__)
+
+if __name__ == '__main__':
+    (options, args) = parser.parse_args()
+    countloc(args)

Modified: py/dist/py/misc/cmdline/countloc.py
==============================================================================
--- py/dist/py/misc/cmdline/countloc.py	(original)
+++ py/dist/py/misc/cmdline/countloc.py	Thu Jan 11 16:58:55 2007
@@ -66,11 +66,10 @@
    
     return counter, numfiles, numlines, numtestfiles, numtestlines
 
-def countloc():
-    args = py.std.sys.argv[1:]
-    if not args: 
-        args = ['.']
-    locations = [py.path.local(x) for x in args]
+def countloc(paths=None):
+    if not paths:
+        paths = ['.']
+    locations = [py.path.local(x) for x in paths]
     (counter, numfiles, numlines, numtestfiles,
      numtestlines) = get_loccount(locations)
 


More information about the py-svn mailing list