X-Git-Url: https://git.libre-soc.org/?p=utils.git;a=blobdiff_plain;f=src%2Fbudget_sync%2Fmain.py;h=e18e07208473f6200edbfaebec6cd03284e5544a;hp=36b485f90af941bc26d1ce8f344521c08dc85c80;hb=df61adb514d7e33819e3672eebf6fde279118d2c;hpb=59fed33efb20451aca6cbc8db8dd1db98aaf08b5 diff --git a/src/budget_sync/main.py b/src/budget_sync/main.py index 36b485f..e18e072 100644 --- a/src/budget_sync/main.py +++ b/src/budget_sync/main.py @@ -1,22 +1,51 @@ from bugzilla import Bugzilla import logging +import argparse +from pathlib import Path from budget_sync.util import all_bugs -from budget_sync.budget_graph import BudgetGraph - - -BUGZILLA_URL = "https://bugs.libre-soc.org" +from budget_sync.config import Config, ConfigParseError +from budget_sync.budget_graph import BudgetGraph, BudgetGraphBaseError +from budget_sync.write_budget_markdown import write_budget_markdown def main(): - logging.info("Using Bugzilla instance at %s", BUGZILLA_URL) - bz = Bugzilla(BUGZILLA_URL) + parser = argparse.ArgumentParser( + description="Check for errors in " + "Libre-SOC's style of budget tracking in Bugzilla.") + parser.add_argument( + "-c", "--config", type=argparse.FileType('r'), + required=True, help="The path to the configuration TOML file", + dest="config", metavar="") + parser.add_argument( + "-o", "--output-dir", type=Path, default=None, + help="The path to the output directory, will be created if it " + "doesn't exist", + dest="output_dir", metavar="") + args = parser.parse_args() + try: + with args.config as config_file: + config = Config.from_file(config_file) + except (IOError, ConfigParseError) as e: + logging.error("Failed to parse config file: %s", e) + return + logging.info("Using Bugzilla instance at %s", config.bugzilla_url) + bz = Bugzilla(config.bugzilla_url) logging.debug("Connected to Bugzilla") - print(bz.getbug(269).__dict__) - print(bz.getbug(1).__dict__) - return - budget_graph = BudgetGraph(all_bugs(bz)) - print(budget_graph) + budget_graph = BudgetGraph(all_bugs(bz), config) + for error in budget_graph.get_errors(): + logging.error("%s", error) + if args.output_dir is not None: + write_budget_markdown(budget_graph, args.output_dir) + # quick hack to display total payment amounts per-milestone + for milestone, payments in budget_graph.milestone_payments.items(): + print (milestone) + print () + total = 0 + for payment in payments: + print("\t", payment) + total += payment.amount + print ("\t", total) if __name__ == "__main__": main()