|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import argparse |
| 3 | +import defusedxml.ElementTree as ET |
| 4 | +import spotbugsSummary |
| 5 | + |
| 6 | + |
| 7 | +def print_comparison(old: dict, new: dict, link_base: str, link_new: str): |
| 8 | + all_keys = sorted(set(list(old.keys()) + list(new.keys()))) |
| 9 | + |
| 10 | + output = "<table><tr><th>Category</th>" |
| 11 | + old_header = f"<a href='{link_base}'>Base</a>" if link_base is not None else "Base" |
| 12 | + output += f"<th>{old_header}</th>" |
| 13 | + new_header = f"<a href='{link_new}'>New</a>" if link_new is not None else "New" |
| 14 | + output += f"<th>{new_header}</th>" |
| 15 | + output += "</tr>" |
| 16 | + |
| 17 | + for category in all_keys: |
| 18 | + category_count_old = old[category] if category in old else 0 |
| 19 | + category_count_new = new[category] if category in new else 0 |
| 20 | + new_str = f"<b>{category_count_new}</b>" if category_count_new != category_count_old else str(category_count_new) |
| 21 | + output += "<tr>" |
| 22 | + output += f"<td>{category}</td>" |
| 23 | + output += f"<td>{category_count_old}</td>" |
| 24 | + output += f"<td>{new_str}</td>" |
| 25 | + output += "</tr>" |
| 26 | + |
| 27 | + output += "<tr>" |
| 28 | + output += "<td><b>Total</b></td>" |
| 29 | + output += f"<td><b>{sum(old.values())}</b></td>" |
| 30 | + output += f"<td><b>{sum(new.values())}</b></td>" |
| 31 | + output += "</tr>" |
| 32 | + |
| 33 | + output += "</table>" |
| 34 | + |
| 35 | + print(output) |
| 36 | + |
| 37 | + |
| 38 | +if __name__ == "__main__": |
| 39 | + parser = argparse.ArgumentParser() |
| 40 | + parser.add_argument("base_file", help="base file for comparison") |
| 41 | + parser.add_argument("new_file", help="new file for comparison") |
| 42 | + parser.add_argument("--link-base", help="http link to base html report") |
| 43 | + parser.add_argument("--link-new", help="http link to new html report") |
| 44 | + args = parser.parse_args() |
| 45 | + |
| 46 | + base_tree = ET.parse(args.base_file) |
| 47 | + base_summary = spotbugsSummary.get_counts(base_tree) |
| 48 | + |
| 49 | + new_tree = ET.parse(args.new_file) |
| 50 | + new_summary = spotbugsSummary.get_counts(new_tree) |
| 51 | + |
| 52 | + print_comparison(base_summary, new_summary, args.link_base, args.link_new) |
0 commit comments