diff --git a/pystat.py b/pystat.py index f365348..aaad807 100755 --- a/pystat.py +++ b/pystat.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# pystat.py +# pystat.py - Count Program And Comment Lines In A Python Program # Copyright (c) 2010 TundraWare Inc. # For Updates See: http://www.tundraware.com/Software/pystat @@ -8,7 +8,7 @@ PROGNAME = "pystat" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: pystat.py,v 1.100 2010/02/18 00:58:55 tundra Exp $" +RCSID = "$Id: pystat.py,v 1.101 2010/02/18 01:18:46 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -40,7 +40,6 @@ import getopt import os import sys -import tconfpy #----------------------------------------------------------# @@ -101,11 +100,10 @@ # Usage Prompts ##### -uTable = [PROGVER, +uTable = [PROGVER + " - Count Program And Comment Lines In A Python Program", HOMEPAGE, - "usage: " + PROGNAME + " [-fhv]", + "usage: " + PROGNAME + " [-fhv] file, file, ...", " where,", - " -f file configuration file to use", " -h print this help information", " -v print detailed version information", ] @@ -115,7 +113,6 @@ # Global Variables & Data Structures # #----------------------------------------------------------# -CFGFILE = os.path.join(os.getenv("HOME"), "." + PROGNAME) # conf file #--------------------------- Code Begins Here ---------------------------------# @@ -184,6 +181,16 @@ ##### +# Print An Error Message +##### + +def InfoMsg(imsg): + PrintStderr(PROGNAME + ": " + imsg) + +# End of 'InfoMsg()' + + +##### # Print To stderr ##### @@ -242,16 +249,25 @@ print RCSID sys.exit(0) -# Process the configuration file -retval = tconfpy.ParseConfig(CFGFILE, CallingProgram="%s %s " % (PROGNAME, VERSION)) +for filename in args: -# Print any errors or warning generated by the parse + f = open(filename) + lines = f.readlines() + f.close() -for x in (retval.ErrMsgs, retval.WarnMsgs): - for y in x: - print y + program = 0 + comment = 0 + total = 0 + for line in lines: -# If there were any errors, we're done -if retval.ErrMsgs: - sys.exit(0) + total += 1 + l = line.split("#") + if len(l) == 1: + if l[0].strip(): + program += 1 + + else: + comment += 1 + + InfoMsg("'%s': %s Program Lines %s Comments %s Total" % (filename, program, comment, total))