add detail option and convert to <tt> and <br>
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 6 Dec 2023 18:25:04 +0000 (18:25 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 6 Dec 2023 18:25:04 +0000 (18:25 +0000)
src/budget_sync/main.py

index b76e6af8970a39e86739c474b6b84533ffe42b43..7b8d6ce78675318383b169eb6151e6a920cdf869 100644 (file)
@@ -15,6 +15,9 @@ from budget_sync.budget_graph import BudgetGraph, PaymentSummary
 from budget_sync.write_budget_markdown import (write_budget_markdown,
                                                markdown_for_person)
 
+def spc(s):
+    return s.replace(" ", "&nbsp;")
+
 
 def main():
     parser = argparse.ArgumentParser(
@@ -41,6 +44,8 @@ def main():
                         help="Log in with this Bugzilla password")
     parser.add_argument('--comments', action='store_true',
                         help="Put JSON into comments")
+    parser.add_argument('--detail', action='store_true',
+                        help="Add detail to report (links description people)")
     args = parser.parse_args()
     try:
         with args.config as config_file:
@@ -54,7 +59,7 @@ def main():
     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
+        print("<tt>", file=f)  # for using the output as markdown
         bz = Bugzilla(config.bugzilla_url)
         if args.username:
             logging.debug("logging in...")
@@ -73,8 +78,8 @@ def main():
         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
+        summarize_milestones(f, budget_graph, detail=args.detail)
+        print("</tt>", 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)
 
@@ -97,7 +102,7 @@ def print_markdown_for_person(f, budget_graph, config, person_str, subset_str):
     print(markdown_for_person(budget_graph, person, nodes_subset), file=f)
 
 
-def print_budget_then_children(f, indent, nodes, bug_id):
+def print_budget_then_children(f, indent, nodes, bug_id, detail=False):
     """recursive indented printout of budgets
     """
 
@@ -119,44 +124,51 @@ def print_budget_then_children(f, indent, nodes, bug_id):
     excl_desc = "               "
     if b_incl != b_excl:
         excl_desc = "excltasks %6s" % b_excl
-    print("bug #%5d %s budget %6s %s %s" %
-          (bug.bug.id, ' |   ' * indent,
-           b_incl,
-           excl_desc,
-           descr
-           ), file=f)
+    print(spc("bug #%5d %s budget %6s %s %s<br>" %
+              (bug.bug.id, ' |   ' * indent,
+               b_incl,
+               excl_desc,
+               descr
+               )), file=f)
+    if detail:
+        print(spc("           %s |      (%s)<br>" %
+                  (' |   ' * indent,
+                   bug.bug.summary[:40]
+                  )), 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(f, indent+1, nodes, child.bug.id)
+        print_budget_then_children(f, indent+1, nodes, child.bug.id, detail)
 
 
-def summarize_milestones(f, budget_graph):
+def summarize_milestones(f, budget_graph, detail=False):
     for milestone, payments in budget_graph.milestone_payments.items():
         summary = PaymentSummary(payments)
-        print(f"{milestone.identifier}", file=f)
+        print(f"{milestone.identifier}<br>", file=f)
         print(f"\t{summary.total} submitted: "
-              f"{summary.total_submitted} paid: {summary.total_paid}", file=f)
+              f"{summary.total_submitted} paid: {summary.total_paid}<br>",
+              file=f)
         not_submitted = summary.get_not_submitted()
         if not_submitted:
-            print("not submitted", not_submitted, file=f)
+            print("not submitted<br>", not_submitted, file=f)
 
         # and one to display people
         for person in budget_graph.milestone_people[milestone]:
-            print("\t%-30s - %s" % (person.identifier, person.full_name),
+            print(spc("\t%-30s - %s<br>" % (person.identifier,
+                                            person.full_name)),
                   file=f)
-        print(file=f)
+        print("<br>", file=f)
 
     # now do trees
     for milestone, payments in budget_graph.milestone_payments.items():
-        print("%s %d" % (milestone.identifier, milestone.canonical_bug_id),
+        print("%s %d<br>" % (milestone.identifier, milestone.canonical_bug_id),
               file=f)
         print_budget_then_children(f, 0, budget_graph.nodes,
-                                   milestone.canonical_bug_id)
-        print(file=f)
+                                   milestone.canonical_bug_id, detail)
+        print("<br>", file=f)
 
 
 def json_milestones(budget_graph: BudgetGraph, add_comments: bool,