#!/usr/bin/env python3
import argparse
import defusedxml.ElementTree as ET
import spotbugsSummary
def print_comparison(old: dict, new: dict, link_base: str, link_new: str):
all_keys = sorted(set(list(old.keys()) + list(new.keys())))
output = "
Category | "
old_header = f"Base" if link_base is not None else "Base"
output += f"{old_header} | "
new_header = f"New" if link_new is not None else "New"
output += f"{new_header} | "
output += "
"
for category in all_keys:
category_count_old = old[category] if category in old else 0
category_count_new = new[category] if category in new else 0
new_str = f"{category_count_new}" if category_count_new != category_count_old else str(category_count_new)
output += ""
output += f"{category} | "
output += f"{category_count_old} | "
output += f"{new_str} | "
output += "
"
output += ""
output += "Total | "
output += f"{sum(old.values())} | "
output += f"{sum(new.values())} | "
output += "
"
output += "
"
print(output)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("base_file", help="base file for comparison")
parser.add_argument("new_file", help="new file for comparison")
parser.add_argument("--link-base", help="http link to base html report")
parser.add_argument("--link-new", help="http link to new html report")
args = parser.parse_args()
base_tree = ET.parse(args.base_file)
base_summary = spotbugsSummary.get_counts(base_tree)
new_tree = ET.parse(args.new_file)
new_summary = spotbugsSummary.get_counts(new_tree)
print_comparison(base_summary, new_summary, args.link_base, args.link_new)