add recursive tree-print of budgets
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 16 Jun 2022 14:00:24 +0000 (15:00 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 16 Jun 2022 14:00:24 +0000 (15:00 +0100)
src/budget_sync/main.py

index c8929aff18d27d400436809078deba0ecd692188..6d587a2d44abd766898c6ce1d943a86655401980 100644 (file)
@@ -4,6 +4,7 @@ from bugzilla import Bugzilla
 import logging
 import argparse
 from pathlib import Path
+from budget_sync.money import Money
 from budget_sync.util import all_bugs
 from budget_sync.config import Config, ConfigParseError, Milestone
 from budget_sync.budget_graph import BudgetGraph, BudgetGraphBaseError, PaymentSummary
@@ -47,6 +48,23 @@ def main():
     summarize_milestones(budget_graph)
 
 
+def print_budget_then_children(indent, nodes, bug_id):
+    """recursive indented printout of budgets
+    """
+
+    bug = nodes[bug_id]
+    print("bug #%5d %s budget %7s excltasks %7s" % \
+            (bug.bug.id, ' ' * (indent*4),
+             str(bug.budget_including_subtasks),
+             str(bug.budget_excluding_subtasks)))
+    #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)
+
+
 def summarize_milestones(budget_graph: BudgetGraph):
     for milestone, payments in budget_graph.milestone_payments.items():
         summary = PaymentSummary(payments)
@@ -59,6 +77,12 @@ def summarize_milestones(budget_graph: BudgetGraph):
             print(f"\t{person.identifier}")
         print()
 
+    # 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,
+                                   milestone.canonical_bug_id)
+        print()
 
 if __name__ == "__main__":
     main()