bug #1171: output record to temp file /tmp/report.mdwn temporarily
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 4 Dec 2023 16:19:26 +0000 (16:19 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 4 Dec 2023 16:19:26 +0000 (16:19 +0000)
https://bugs.libre-soc.org/show_bug.cgi?id=1171
all output going temporarily to a report.mdwn, TODO to make it an
option on the commandline, this is so that report.mdwn (summary)
can be joined by a *second* more detailed report (or an option
to create one)

src/budget_sync/main.py

index 5d6aac191f90db708ac256cfe33e25430b9b359b..96e0f2745cfa8bf0a85b8ef12c989fef9815337a 100644 (file)
@@ -49,7 +49,8 @@ def main():
         logging.error("Failed to parse config file: %s", e)
         return
     logging.info("Using Bugzilla instance at %s", config.bugzilla_url)
-    print("```")  # for using the output as markdown
+    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...")
@@ -62,19 +63,18 @@ def main():
         if not args.person:
             logging.fatal("must use --subset-person with --subset option")
             sys.exit(1)
-        print_markdown_for_person(budget_graph, config,
+        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(budget_graph)
-    print("```")  # for using the output as markdown
+    summarize_milestones(f, budget_graph)
+    print("```", file=f)  # for using the output as markdown
     json_milestones(budget_graph, args.comments, args.output_dir)
 
 
-def print_markdown_for_person(budget_graph: BudgetGraph, config: Config,
-                              person_str: str, subset_str: Optional[str]):
+def print_markdown_for_person(f, budget_graph, config, person_str, subset_str):
     person = config.all_names.get(person_str)
     if person is None:
         logging.fatal("--subset-person: unknown person: %s", person_str)
@@ -89,10 +89,10 @@ def print_markdown_for_person(budget_graph: BudgetGraph, config: Config,
                 logging.fatal("--subset: unknown bug: %s", bug_id)
                 sys.exit(1)
             nodes_subset.add(node)
-    print(markdown_for_person(budget_graph, person, nodes_subset))
+    print(markdown_for_person(budget_graph, person, nodes_subset), file=f)
 
 
-def print_budget_then_children(indent, nodes, bug_id):
+def print_budget_then_children(f, indent, nodes, bug_id):
     """recursive indented printout of budgets
     """
 
@@ -119,37 +119,39 @@ def print_budget_then_children(indent, nodes, bug_id):
            b_incl,
            excl_desc,
            descr
-           ))
+           ), file=f)
     # print(repr(bug))
 
     for child in bug.immediate_children:
         if (str(child.budget_including_subtasks) == "0" and
                 str(child.budget_excluding_subtasks) == "0"):
             continue
-        print_budget_then_children(indent+1, nodes, child.bug.id)
+        print_budget_then_children(f, indent+1, nodes, child.bug.id)
 
 
-def summarize_milestones(budget_graph: BudgetGraph):
+def summarize_milestones(f, budget_graph):
     for milestone, payments in budget_graph.milestone_payments.items():
         summary = PaymentSummary(payments)
-        print(f"{milestone.identifier}")
+        print(f"{milestone.identifier}", file=f)
         print(f"\t{summary.total} submitted: "
-              f"{summary.total_submitted} paid: {summary.total_paid}")
+              f"{summary.total_submitted} paid: {summary.total_paid}", file=f)
         not_submitted = summary.get_not_submitted()
         if not_submitted:
-            print("not submitted", not_submitted)
+            print("not submitted", not_submitted, file=f)
 
         # and one to display people
         for person in budget_graph.milestone_people[milestone]:
-            print(f"\t%-30s - %s" % (person.identifier, person.full_name))
-        print()
+            print("\t%-30s - %s" % (person.identifier, person.full_name),
+                  file=f)
+        print(file=f)
 
     # now do trees
     for milestone, payments in budget_graph.milestone_payments.items():
-        print("%s %d" % (milestone.identifier, milestone.canonical_bug_id))
-        print_budget_then_children(0, budget_graph.nodes,
+        print("%s %d" % (milestone.identifier, milestone.canonical_bug_id),
+              file=f)
+        print_budget_then_children(f, 0, budget_graph.nodes,
                                    milestone.canonical_bug_id)
-        print()
+        print(file=f)
 
 
 def json_milestones(budget_graph: BudgetGraph, add_comments: bool,