a quick hack to display total payments per milestone
[utils.git] / src / budget_sync / main.py
index 412f21c297a3048c083a3ad65f739410021af485..e18e07208473f6200edbfaebec6cd03284e5544a 100644 (file)
@@ -1,12 +1,11 @@
 from bugzilla import Bugzilla
 import logging
 import argparse
+from pathlib import Path
 from budget_sync.util import all_bugs
 from budget_sync.config import Config, ConfigParseError
 from budget_sync.budget_graph import BudgetGraph, BudgetGraphBaseError
-
-
-BUGZILLA_URL = "https://bugs.libre-soc.org"
+from budget_sync.write_budget_markdown import write_budget_markdown
 
 
 def main():
@@ -14,9 +13,14 @@ def main():
         description="Check for errors in "
         "Libre-SOC's style of budget tracking in Bugzilla.")
     parser.add_argument(
-        "-c--config", type=argparse.FileType('r'),
+        "-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:
@@ -30,7 +34,18 @@ def main():
     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()