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="<path/to/budget-sync-config.toml>")
+ 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="<path/to/output/dir>")
+ 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()