From 9f3c0923804d72c55c400cb5c76c201261b1c2b9 Mon Sep 17 00:00:00 2001 From: Robin Avery Date: Sat, 10 Aug 2024 16:59:58 -0400 Subject: [PATCH] Create script to generate wiki translation unit list Can be automated and/or expanded on later. --- tools/wiki_tu.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 tools/wiki_tu.py diff --git a/tools/wiki_tu.py b/tools/wiki_tu.py new file mode 100755 index 0000000000..529c7d6d65 --- /dev/null +++ b/tools/wiki_tu.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +import argparse +import json +import sys +from pathlib import Path + +import humanfriendly + + +def write(args): + if args.report_path == "-": + data = json.load(sys.stdin) + else: + path = Path(args.report_path) + data = json.load(path.open("r")) + print( + """# Translation Units + +Edit this page and fill in your own username to assign yourself to a file. + +File|Matched|Total|%|:grey_question:|Assignee
Discord|Assignee
GitHub +-|-|-|-|-|-|-""" + ) + for unit in data["units"] or []: + + def friendly_size(key: str) -> str: + return f"`{humanfriendly.format_number(unit[key] or 0)}`" + + # Strip "main/" by splitting on "/" and recombining + file = "/".join((unit["name"] or "/").split("/")[1:]) + # Link to source file + file = f"[`{file}`](../../tree/master/src/{file}.c)" + + matched = f"{friendly_size('matched_code')}" + total = f"{friendly_size('total_code')}" + percent = f"`{humanfriendly.round_number(unit['fuzzy_match_percent'] or 0)}%`" + linked = ":heavy_check_mark:" if unit["complete"] else ":x:" + print( + f"{file}|{matched}|{total}|{percent}|{linked}" + "||" + ) + + +def main(): + parser = argparse.ArgumentParser( + description="Generates and parses the wiki's list of translation units." + ) + subparsers = parser.add_subparsers(dest="subcommand") + + parser_write = subparsers.add_parser("write", help="Write JSON data to a file.") + parser_write.add_argument( + "report_path", + metavar="REPORT", + nargs="?", + const="-", + default=None, + type=str, + help="Path to the JSON report generated by objdiff-cli.", + ) + parser_write.set_defaults(func=write) + + args = parser.parse_args() + args.func(args) + + +if __name__ == "__main__": + main()