1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#! /usr/bin/env python
# VIM declarations
# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:
#must be first
from __future__ import division
import re
import sys
import glob
import os
def processFile( filename ):
pct = 0
lineCount = 0
linesOfCode = 0
statementsExecuted = 0
fd = file( filename, "r" )
while 1:
line = fd.readline()
if line == "":
break
lineCount = lineCount + 1
p = re.match( "^\s*-:", line )
if p is not None:
continue
p = re.match( "^\s{0,9}\d+:", line )
if p is not None:
linesOfCode = linesOfCode + 1
statementsExecuted = statementsExecuted + 1
continue
p = re.match( "^ #####:", line )
if p is not None:
linesOfCode = linesOfCode + 1
if linesOfCode == 0:
pct = 1
else:
pct = statementsExecuted / linesOfCode
return ( pct, lineCount, linesOfCode, statementsExecuted )
def main():
totalLines = 0
totalLoc = 0
totalExc = 0
path = sys.argv[1] + "/libraries*"
fileList = glob.glob( path )
print " PCT\tLINES\tCODE\tEXEC\tFILENAME"
for file in fileList:
(pct, lines, loc, exc) = processFile( file )
totalLines = totalLines + lines
totalLoc = totalLoc + loc
totalExc = totalExc + exc
file = os.path.basename(file)
file = file[:-5]
print "%3.0f%%\t%d\t%d\t%d\t%s" % ( (pct*100), lines, loc, exc, file )
if totalLoc == 0:
pct = 1
else:
pct = totalExc / totalLoc
print
print "%3.0f%%\t%d\t%d\t%d\t%s" % ( (pct*100), totalLines, totalLoc, totalExc, "TOTAL" )
if __name__ == "__main__":
main()
|