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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#! /usr/bin/env python
# Copyright (c) 2017 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
import sys
import os
import pprint
import subprocess
import difflib
import csv
import argparse
sys.path.append("@INSTALL_PYTHON_DIR@")
sys.path.append("@DEPENDENCY_PYTHON_DIR@")
import LongBow
def concatenateContinuationLines(lines):
'''
Parse doxygen log lines.
Lines that are indented by a space are continutations of the previous line.
'''
result = list()
accumulator = ""
for line in lines:
line = line.rstrip()
if line.startswith(" ") == False and line.startswith(" ") == False:
if len(accumulator) > 0:
result.append(accumulator)
accumulator = line
else:
accumulator = accumulator + " " + line.lstrip()
result.append(accumulator)
return result
def parseLine(line):
result = None
if not line.startswith("<"):
fields = line.split(":")
if len(fields) >= 4:
result = { "fileName" : fields[0].strip(),
"lineNumber" : int(fields[1].strip()),
"type" : "documentation",
"severity" : fields[2].strip(),
"message" : " ".join(fields[3:]).strip()}
elif line.startswith("error"):
print line
elif len(line) > 0:
print "Consider using doxygen -s:", line
return result
def canonicalize(lines):
lines = concatenateContinuationLines(lines)
parsedLines = map(lambda line: parseLine(line), lines)
parsedLines = filter(lambda line: line != None, parsedLines)
return parsedLines
def organize(entries):
result = dict()
for entry in entries:
if not entry["fileName"] in result:
result[entry["fileName"]] = dict()
entryByFile = result[entry["fileName"]]
if not str(entry["lineNumber"]) in entryByFile:
entryByFile[str(entry["lineNumber"])] = list()
if not entry in entryByFile[str(entry["lineNumber"])]:
entryByFile[str(entry["lineNumber"])].append(entry)
return result
def textualSummary(distribution, documentation):
maxWidth = 0
for entry in documentation:
if len(entry) > maxWidth:
maxWidth = len(entry)
formatString ="%-" + str(maxWidth) + "s %8d %8d %.2f%%"
for entry in documentation:
badLines = len(documentation[entry])
totalLines = LongBow.countLines(entry)
score = float(totalLines - badLines) / float(totalLines) * 100.0
LongBow.scorePrinter(distribution, score, formatString % (entry, totalLines, badLines, score))
return
def textualAverage(distribution, documentation, format):
sum = 0.0
for entry in documentation:
badLines = len(documentation[entry])
totalLines = LongBow.countLines(entry)
score = float(totalLines - badLines) / float(totalLines) * 100.0
sum = sum + score
if len(documentation) == 0:
averageScore = 100.0
else:
averageScore = sum / float(len(documentation))
LongBow.scorePrinter(distribution, averageScore, format % averageScore)
def csvSummary(distribution, documentation):
formatString ="documentation,%s,%d,%d,%.2f%%"
for entry in documentation:
badLines = len(documentation[entry])
totalLines = LongBow.countLines(entry)
score = float(totalLines - badLines) / float(totalLines) * 100.0
LongBow.scorePrinter(distribution, score, formatString % (entry, totalLines, badLines, score))
return
def main(argv):
parser = argparse.ArgumentParser(prog='longbow-doxygen-report', formatter_class=argparse.RawDescriptionHelpFormatter, description="")
parser.add_argument('-l', '--doxygenlog', default=False, action="store", required=True, type=str, help="The doxygen output log to use.")
parser.add_argument('-s', '--summary', default=False, action="store_true", required=False, help="Produce the score for each file")
parser.add_argument('-a', '--average', default=False, action="store_true", required=False, help="Produce the simple average of all scores.")
parser.add_argument('-d', '--distribution', default="[100, 95]", action="store", required=False, type=str, help="A list containing the score distributions for pretty-printing")
parser.add_argument('-o', '--output', default="text", action="store", required=False, type=str, help="The required output format. text, csv")
args = parser.parse_args()
if not args.summary and not args.average:
args.summary = True
with open(args.doxygenlog, 'r') as f:
lines = f.readlines()
lines = canonicalize(lines)
result = organize(lines)
pp = pprint.PrettyPrinter(indent=4)
#pp.pprint(result)
distribution = eval(args.distribution)
if args.summary:
if args.output == "text":
textualSummary(distribution, result)
else:
csvSummary(distribution, result)
if args.average:
textualAverage(distribution, result, "%.2f")
if __name__ == '__main__':
'''
@(#) longbow-doxygen-report @VERSION@ @DATE@
@(#) All Rights Reserved. Use is subject to license terms.
'''
main(sys.argv)
|