Skip to content

Commit 2cc0bc7

Browse files
wip
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent 56ab7be commit 2cc0bc7

2 files changed

Lines changed: 122 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
# SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
3+
# SPDX-FileCopyrightText: 2017 Tobias Kaminsky <tobias@kaminsky.me>
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
import argparse
6+
import defusedxml.ElementTree as ET
7+
8+
import spotbugsSummary
9+
10+
11+
def print_comparison(old: dict, new: dict, link_base: str, link_new: str):
12+
all_keys = sorted(set(list(old.keys()) + list(new.keys())))
13+
14+
output = "<table><tr><th>Category</th>"
15+
old_header = f"<a href='{link_base}'>Base</a>" if link_base is not None else "Base"
16+
output += f"<th>{old_header}</th>"
17+
new_header = f"<a href='{link_new}'>New</a>" if link_new is not None else "New"
18+
output += f"<th>{new_header}</th>"
19+
output += "</tr>"
20+
21+
for category in all_keys:
22+
category_count_old = old[category] if category in old else 0
23+
category_count_new = new[category] if category in new else 0
24+
new_str = f"<b>{category_count_new}</b>" if category_count_new != category_count_old else str(
25+
category_count_new)
26+
output += "<tr>"
27+
output += f"<td>{category}</td>"
28+
output += f"<td>{category_count_old}</td>"
29+
output += f"<td>{new_str}</td>"
30+
output += "</tr>"
31+
32+
output += "<tr>"
33+
output += "<td><b>Total</b></td>"
34+
output += f"<td><b>{sum(old.values())}</b></td>"
35+
output += f"<td><b>{sum(new.values())}</b></td>"
36+
output += "</tr>"
37+
38+
output += "</table>"
39+
40+
print(output)
41+
42+
43+
if __name__ == "__main__":
44+
parser = argparse.ArgumentParser()
45+
parser.add_argument("base_file", help="base file for comparison")
46+
parser.add_argument("new_file", help="new file for comparison")
47+
parser.add_argument("--link-base", help="http link to base html report")
48+
parser.add_argument("--link-new", help="http link to new html report")
49+
args = parser.parse_args()
50+
51+
base_tree = ET.parse(args.base_file)
52+
base_summary = spotbugsSummary.get_counts(base_tree)
53+
54+
new_tree = ET.parse(args.new_file)
55+
new_summary = spotbugsSummary.get_counts(new_tree)
56+
57+
print_comparison(base_summary, new_summary, args.link_base, args.link_new)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python3
2+
# SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
3+
# SPDX-FileCopyrightText: 2017 Tobias Kaminsky <tobias@kaminsky.me>
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
import argparse
6+
import defusedxml.ElementTree as ET
7+
8+
9+
def get_counts(tree):
10+
category_counts = {}
11+
category_names = {}
12+
for child in tree.getroot():
13+
if child.tag == "BugInstance":
14+
category = child.attrib['category']
15+
if category in category_counts:
16+
category_counts[category] = category_counts[category] + 1
17+
else:
18+
category_counts[category] = 1
19+
elif child.tag == "BugCategory":
20+
category = child.attrib['category']
21+
category_names[category] = child[0].text
22+
23+
summary = {}
24+
for category in category_counts.keys():
25+
summary[category_names[category]] = category_counts[category]
26+
return summary
27+
28+
29+
def print_html(summary):
30+
output = "<table><tr><th>Category</th><th>Count</th></tr>"
31+
32+
categories = sorted(summary.keys())
33+
for category in categories:
34+
output += "<tr>"
35+
output += f"<td>{category}</td>"
36+
output += f"<td>{summary[category]}</td>"
37+
output += "</tr>"
38+
39+
output += "<tr>"
40+
output += "<td><b>Total</b></td>"
41+
output += f"<td><b>{sum(summary.values())}</b></td>"
42+
output += "</tr>"
43+
44+
output += "</table>"
45+
46+
print(output)
47+
48+
49+
def print_total(summary):
50+
print(sum(summary.values()))
51+
52+
53+
if __name__ == "__main__":
54+
parser = argparse.ArgumentParser()
55+
parser.add_argument("--total", help="print total count instead of summary HTML",
56+
action="store_true")
57+
parser.add_argument("--file", help="file to parse",
58+
default="app/build/reports/spotbugs/gplayDebug.xml")
59+
args = parser.parse_args()
60+
tree = ET.parse(args.file)
61+
summary = get_counts(tree)
62+
if args.total:
63+
print_total(summary)
64+
else:
65+
print_html(summary)

0 commit comments

Comments
 (0)