From: Luke Kenneth Casson Leighton Date: Sat, 16 Jul 2022 14:06:06 +0000 (+0100) Subject: add dump-option for milestones in JSON format X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ee2c2bcfd9e6e762c85ebd2f3e1fbeccb814c112;p=utils.git add dump-option for milestones in JSON format --- diff --git a/src/budget_sync/main.py b/src/budget_sync/main.py index 6b37d03..12ce493 100644 --- a/src/budget_sync/main.py +++ b/src/budget_sync/main.py @@ -1,6 +1,7 @@ import os import re import sys +import json from typing import Optional from budget_sync.ordered_set import OrderedSet from budget_sync.write_budget_csv import write_budget_csv @@ -66,6 +67,7 @@ def main(): write_budget_markdown(budget_graph, args.output_dir) write_budget_csv(budget_graph, args.output_dir) summarize_milestones(budget_graph) + json_milestones(budget_graph) def print_markdown_for_person(budget_graph: BudgetGraph, config: Config, @@ -132,5 +134,61 @@ def summarize_milestones(budget_graph: BudgetGraph): print ("```") # for using the output as markdown +def json_milestones(budget_graph): + """reports milestones as json format + """ + for milestone, payments in budget_graph.milestone_payments.items(): + summary = PaymentSummary(payments) + # and one to display people + ppl = [] + for person in budget_graph.milestone_people[milestone]: + p = {'name': person.full_name, 'email': person.email} + ppl.append(p) + + tasks = [] + canonical = budget_graph.nodes[milestone.canonical_bug_id] + for child in canonical.immediate_children: + milestones = [] + # include the task itself as a milestone + for st in [child] + list(child.children()): + amount = st.fixed_budget_including_subtasks.int() + if amount == 0: # skip anything at zero + continue + task = {'description': "%d %s" % (st.bug.id, st.bug.summary), + 'intro': [], + 'amount': amount, + 'url': st.bug_url, + } + # add parent and MoU top-level + parent_id = st.parent.bug.id, + if parent_id != milestone.canonical_bug_id: + task['parent'] = parent_id + mou_bug = st.closest_bug_in_mou + if mou_bug is not None: + task['mou_task'] = mou_bug.bug.id + milestones.append(task) + # create MoU task + task = {'title': "%d %s" % (child.bug.id, child.bug.summary), + 'intro': [], + 'amount': child.fixed_budget_including_subtasks.int(), + 'url': child.bug_url, + 'milestones': milestones + } + tasks.append(task) + + d = {'participants': ppl, + 'preamble': '', + 'type': 'Group', + 'plan': { 'intro': [''], + 'tasks': tasks, + 'rfp_secret': '', + } + } + + with open("report.%s.json" % milestone.identifier, "w") as f: + json.dump(d, f, indent=2) + + + if __name__ == "__main__": main() diff --git a/src/budget_sync/money.py b/src/budget_sync/money.py index 7f62b7a..772e8ca 100644 --- a/src/budget_sync/money.py +++ b/src/budget_sync/money.py @@ -81,6 +81,9 @@ class Money: cents = -cents return Money(cents=cents) + def int(self): + return int(str(self)) + def __str__(self): retval = "-" if self.cents < 0 else "" retval += str(abs(self.cents) // CENTS_PER_EURO)