-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarning_stats.py
executable file
·54 lines (43 loc) · 1.48 KB
/
warning_stats.py
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
#!/usr/bin/env python3
import argparse
from collections import defaultdict
import os
# Requires pip package warning-parser:
# https://pypi.org/project/warning-parser/
import warning_parser
def parse_args():
parser = argparse.ArgumentParser(
prog="Warning Statistics",
description="""
Summarizes warnings generated by a compiler or linter.
""",
)
parser.add_argument("file", help="File with warnings generated by tool")
parser.add_argument("--tool", help="Type of tool", default="gcc")
return parser.parse_args()
def summarize_topic(topic, warnings_per_topic, printer):
print(topic)
topic_sorted = sorted(
warnings_per_topic.keys(),
key=lambda k: len(warnings_per_topic[k]),
reverse=True,
)
for k in topic_sorted:
printer(k, len(warnings_per_topic[k]))
def main():
args = parse_args()
warnings = warning_parser.get_warnings(args.file, args.tool)
severities = defaultdict(list)
categories = defaultdict(list)
files = defaultdict(list)
for w in warnings:
severities[w.get_severity()].append(w)
categories[w.get_category()].append(w)
files[w.get_filepath()].append(w)
summarize_topic("Severities", severities, lambda k, v: print(f" {v:4d} {k}"))
summarize_topic("Categories", categories, lambda k, v: print(f" {v:4d} {k}"))
summarize_topic(
"Files", files, lambda k, v: print(f" {v:4d} {os.path.basename(k)}")
)
if __name__ == "__main__":
main()