from bugzilla.bug import Bug
-from bugzilla import Bugzilla
from typing import Set, Dict, Iterable, Optional, List, Union, Any
-from budget_sync.util import all_bugs
+from budget_sync.util import BugStatus
from budget_sync.money import Money
from budget_sync.config import Config, Person, Milestone
from functools import cached_property
f"#{self.bug_id}: unknown milestone: {self.milestone_str!r}"
+class BudgetGraphUnknownStatus(BudgetGraphParseError):
+ def __init__(self, bug_id: int, status_str: str):
+ super().__init__(bug_id)
+ self.status_str = status_str
+
+ def __str__(self):
+ return f"failed to parse status field of bug " \
+ f"#{self.bug_id}: unknown status: {self.status_str!r}"
+
+
class Node:
graph: "BudgetGraph"
bug: Bug
if self.milestone_str == "---":
self.milestone_str = None
+ @property
+ def status(self) -> BugStatus:
+ try:
+ return BugStatus.cast(self.bug.status)
+ except ValueError:
+ new_err = BudgetGraphUnknownStatus(self.bug.id, self.bug.status)
+ raise new_err.with_traceback(sys.exc_info()[2])
+
@cached_property
def bug_url(self) -> str:
return f"{self.graph.config.bugzilla_url_stripped}/show_bug.cgi?" \
milestone = repr(self.milestone)
except BudgetGraphBaseError:
milestone = "<unknown milestone>"
+ try:
+ status = repr(self.status)
+ except BudgetGraphBaseError:
+ status = f"<unknown status: {self.bug.status!r}>"
immediate_children = []
for i in self.immediate_children:
immediate_children.append(_NodeSimpleReprWrapper(i))
f"milestone_str={self.milestone_str!r}, "
f"milestone={milestone}, "
f"immediate_children={immediate_children!r}, "
- f"payments={payments!r}")
+ f"payments={payments!r}, "
+ f"status={status})")
class BudgetGraphError(BudgetGraphBaseError):
except BudgetGraphBaseError as e:
errors.append(e)
+ try:
+ # check for status errors
+ node.status
+ except BudgetGraphBaseError as e:
+ errors.append(e)
+
if node.milestone_str != root.milestone_str:
errors.append(BudgetGraphMilestoneMismatch(
node.bug.id, root.bug.id))
for payment in node.payments.values():
retval[payment.payee][node.milestone].append(payment)
return retval
+
+ def __repr__(self):
+ nodes = [*self.nodes.values()]
+ try:
+ roots = [_NodeSimpleReprWrapper(i) for i in self.roots]
+ roots.sort()
+ roots_str = repr(roots)
+ except BudgetGraphBaseError:
+ roots_str = "<failed>"
+ return f"BudgetGraph{{nodes={nodes!r}, roots={roots}}}"