- attachment:deprevive.py of TodoTemplate
Attachment 'deprevive.py'
Download 1 from roundup.date import Interval
2
3 def deprevive_reactor(db, cl, issue_id, oldvals):
4 '''Revives depending issue if an issue is marked as done
5 '''
6
7 waiting_id = db.status.lookup('waiting')
8 done_id = db.status.lookup('done')
9 att_id = db.status.lookup('needs attention')
10 if oldvals.has_key("status") and cl.get(issue_id, "status") == done_id:
11 for id in cl.find(superseder=issue_id):
12 deps = cl.get(id, "superseder")
13 if cl.get(id,"status") == waiting_id and len(deps) == \
14 len([x for x in deps if cl.get(x, "status") == done_id ]):
15 cl.set(id, status=att_id)
16 cl.set(id, revives=None)
17
18
19
20 def deprevive_auditor(db, cl, issue_id, newdata):
21 ''' Checks that:
22 - The revive date is before the due date
23 - If there is no revive date, the due date is later
24 than those of all dependencies
25 - The priority is lower or equal to that of the dependencies
26 '''
27
28 # New priority
29 if newdata.has_key("priority"):
30 priority = newdata["priority"]
31 elif issue_id:
32 priority = cl.get(issue_id, "priority")
33 else:
34 priority = None
35
36 # New superseder
37 if newdata.has_key("superseder"):
38 superseder = newdata["superseder"]
39 elif issue_id:
40 superseder = cl.get(issue_id, "superseder")
41 else:
42 superseder = []
43
44 # New due date
45 if newdata.has_key("due_date"):
46 due_date = newdata["due_date"]
47 elif issue_id:
48 due_date = cl.get(issue_id, "due_date")
49 else:
50 due_date = None
51
52 # New Revives
53 if newdata.has_key("revives"):
54 revives = newdata["revives"]
55 elif issue_id:
56 revives = cl.get(issue_id, "revives")
57 else:
58 revives = None
59
60
61 # Check that the revive date is at least 1 day
62 # before the due date
63 if due_date and revives and due_date - revives < Interval("1d"):
64 raise ValueError, "Revive date must be at least 1 day before due date."
65
66
67 # Check that dependencies have higher or equal priority
68 if newdata.has_key("superseder") or \
69 newdata.has_key("priority"):
70 for id in superseder:
71 if db.issue.get(id, "priority") > priority:
72 raise ValueError, "Depends on issue " + id + " which has lower priority."
73
74 if issue_id:
75 for id in cl.find(superseder=issue_id):
76 if db.issue.get(id, "priority") < priority:
77 raise ValueError, "Depending issue " + id + " has higher priority."
78
79 # Check that dependencies have later due date or or revive date
80 if newdata.has_key("superseder") or \
81 newdata.has_key("due_date") or \
82 newdata.has_key("revives"):
83
84 for id in superseder:
85 if due_date and not revives and (not db.issue.get(id, "due_date") or \
86 due_date - db.issue.get(id, "due_date") < Interval("1d")):
87 raise ValueError, "Depends on issue " + id + " which has later (or no) due_date."
88
89 if issue_id:
90 for id in cl.find(superseder=issue_id):
91 if db.issue.get(id, "due_date") and \
92 not db.issue.get(id, "revives") and \
93 ( not due_date or
94 db.issue.get(id, "due_date") - due_date < Interval("1d") ):
95 raise ValueError, "Issue " + id + " with earlier due date depends on this issue."
96
97 def init(db):
98 db.issue.react('set', deprevive_reactor)
99 db.issue.audit('set', deprevive_auditor)
100 db.issue.audit('create', deprevive_auditor)
101
102 # vim: set filetype=python ts=4 sw=4 et si
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.