File: tr-report.py

package info (click to toggle)
libsmbios 2.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 4,684 kB
  • sloc: ansic: 6,953; xml: 4,275; python: 3,459; cpp: 1,878; makefile: 366; sh: 309
file content (76 lines) | stat: -rwxr-xr-x 1,757 bytes parent folder | download | duplicates (2)
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
76
#! /usr/bin/python3
# VIM declarations
# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:

#must be first


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 = os.path.join(sys.argv[1],  "*.gcov")

    fileList = glob.glob( path )
    fileList.sort()

    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()