bug#1171: output report.mdwn to output_dir, default to ./report.mdwn"
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 4 Dec 2023 16:45:55 +0000 (16:45 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 4 Dec 2023 16:45:55 +0000 (16:45 +0000)
src/budget_sync/main.py

index 96e0f2745cfa8bf0a85b8ef12c989fef9815337a..d646556c6c3959856ee7068b803350c19cc2752d 100644 (file)
@@ -49,28 +49,33 @@ def main():
         logging.error("Failed to parse config file: %s", e)
         return
     logging.info("Using Bugzilla instance at %s", config.bugzilla_url)
-    f = open("/tmp/report.mdwn", "w")
-    print("```", file=f)  # for using the output as markdown
-    bz = Bugzilla(config.bugzilla_url)
-    if args.username:
-        logging.debug("logging in...")
-        bz.interactive_login(args.username, args.password)
-    logging.debug("Connected to Bugzilla")
-    budget_graph = BudgetGraph(all_bugs(bz), config)
-    for error in budget_graph.get_errors():
-        logging.error("%s", error)
-    if args.person or args.subset:
-        if not args.person:
-            logging.fatal("must use --subset-person with --subset option")
-            sys.exit(1)
-        print_markdown_for_person(f, budget_graph, config,
-                                  args.person, args.subset)
-        return
-    if args.output_dir is not None:
-        write_budget_markdown(budget_graph, args.output_dir)
-        write_budget_csv(budget_graph, args.output_dir)
-    summarize_milestones(f, budget_graph)
-    print("```", file=f)  # for using the output as markdown
+    # download all bugs and create a summary report
+    reportdir = "./" if args.output_dir is None else str(args.output_dir)
+    reportdir = "/".join(reportdir.split("/")[:-1]) # strip /mdwn
+    reportname = reportdir + "/report.mdwn"
+    with open(reportname, "w") as f:
+        print("```", file=f)  # for using the output as markdown
+        bz = Bugzilla(config.bugzilla_url)
+        if args.username:
+            logging.debug("logging in...")
+            bz.interactive_login(args.username, args.password)
+        logging.debug("Connected to Bugzilla")
+        budget_graph = BudgetGraph(all_bugs(bz), config)
+        for error in budget_graph.get_errors():
+            logging.error("%s", error)
+        if args.person or args.subset:
+            if not args.person:
+                logging.fatal("must use --subset-person with --subset option")
+                sys.exit(1)
+            print_markdown_for_person(f, budget_graph, config,
+                                      args.person, args.subset)
+            return
+        if args.output_dir is not None:
+            write_budget_markdown(budget_graph, args.output_dir)
+            write_budget_csv(budget_graph, args.output_dir)
+        summarize_milestones(f, budget_graph)
+        print("```", file=f)  # for using the output as markdown
+    # now create the JSON milestone files for putting into NLnet RFP system
     json_milestones(budget_graph, args.comments, args.output_dir)