First cut.
1 parent c4808fd commit 8c40a73d9203bcdc93788a9ea921625b874afd27
@tundra tundra authored on 17 Feb 2010
Showing 1 changed file
View
67
pystat.py
#!/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
 
# Program Information
 
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
 
 
import getopt
import os
import sys
import tconfpy
 
 
#----------------------------------------------------------#
# Aliases & Redefinitions #
#####
# 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",
]
 
#----------------------------------------------------------#
# Global Variables & Data Structures #
#----------------------------------------------------------#
 
CFGFILE = os.path.join(os.getenv("HOME"), "." + PROGNAME) # conf file
 
 
#--------------------------- Code Begins Here ---------------------------------#
 
def ErrorMsg(emsg):
PrintStderr(PROGNAME + " " + eERROR + ": " + emsg)
 
# End of 'ErrorMsg()'
 
 
#####
# Print An Error Message
#####
 
def InfoMsg(imsg):
PrintStderr(PROGNAME + ": " + imsg)
 
# End of 'InfoMsg()'
 
 
#####
# Print To stderr
if opt == "-v":
print RCSID
sys.exit(0)
 
# Process the configuration file
 
retval = tconfpy.ParseConfig(CFGFILE, CallingProgram="%s %s " % (PROGNAME, VERSION))
 
# Print any errors or warning generated by the parse
 
for x in (retval.ErrMsgs, retval.WarnMsgs):
for y in x:
print y
 
# If there were any errors, we're done
if retval.ErrMsgs:
sys.exit(0)
 
for filename in args:
 
f = open(filename)
lines = f.readlines()
f.close()
 
program = 0
comment = 0
total = 0
for line in lines:
 
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))