- attachment:add-issues.py of TodoTemplate
Attachment 'add-issues.py'
Download 1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4
5 # Use this to create repeating issues. It should run once per day with
6 # the tracker directory as its first argument. The script then ensures
7 # that for each of the repeating events described below, there are
8 # corresponding issues with the appropriate due dates in the tracker.
9 #
10 # By default, only the upcoming issue is added to the tracker. That
11 # is, if you have weekly event, the script will not clutter your
12 # tracker with e.g. 52 issues with due dates for each week, but will
13 # only add one issue for the next week. If it is then called again in
14 # the next week, it will add an issue for the week after that etc.
15 #
16 # The events are configured in the list of python dictionaries below.
17 # The keys title, priority, keyword and message should be self
18 # explanatory. Note that there is no support for multiple keywords
19 # yet, but adding this should be trivial.
20 #
21 # When an issue is added to the tracker, it always starts in the
22 # 'waiting' state. The 'revives' key can be used to specify the revive
23 # date relative to the due date. So if you set "revives": -10, then
24 # the issue will change to 'needs attention' 10 days before it is due.
25 #
26 # To configure the periodicity, you can use the keys months,
27 # days_of_month and days_of_week. The event will be repeated on every
28 # date that matches all specified criteria. So if you specify only
29 # "days_of_month": [1,20] it will be added for the 1st and 20th of
30 # every month. If you add "months": [1,12] this will only happen in
31 # January and December. Had you specified *only* "months": [1,12] the
32 # event would be added to every day in January and December. Note that
33 # for days_of_week you should use the 3 letter abbreviations instead
34 # of numbers, i.e. "Mon", "Tue" etc.
35 #
36
37
38 issues = [
39 { "title": "Monthly issue 1",
40 "priority": "normal",
41 "keyword": "PC",
42 "days_of_month": [10,5],
43 "months": [4,8,12],
44 "revives": -5,
45 "message": """
46 This creates issues with due dates on the 10th and 5th
47 of the months 4,8 and 12 (April, August and December).
48 """
49
50 { "title": "Monthly issue 2",
51 "priority": "normal",
52 "keyword": "Privat",
53 "days_of_month": [25,4],
54 "revives": -2,
55 "message": """
56 This creates issues with due dates on the 25th and 4th
57 of every month.
58 """},
59
60 { "title": "Weekly Issue",
61 "priority": "normal",
62 "keyword": "Pulse",
63 "days_of_week": ["Mon", "Tue"],
64 "days_of_month": [3, 16],
65 "revives": -9,
66 "message": """
67 This creates issues whenever the 3th or 16th is a Monday
68 or Tuesday, no matter what month."""},
69 ]
70
71
72
73 #### BEGIN MAIN PROGRAM ####
74
75
76 # Roundup boto uses several deprecated modules
77 import warnings
78 warnings.filterwarnings("ignore", "", DeprecationWarning, "roundup")
79
80 import sys
81 from roundup import instance
82 from roundup.date import Date,Interval
83 from copy import deepcopy
84
85 # open the instance
86 if len(sys.argv) != 2:
87 print 'You need to specify an instance home dir'
88 instance_home = sys.argv[1]
89 instance = instance.open(instance_home)
90 db = instance.open('admin')
91
92 # Remove time from current date
93 now = Date(Date(".").pretty("%Y-%m-%d"))
94
95 # Loop through next 2 months and add issues
96 for offset in [Interval("%dd" % x) for x in range(1,60)]:
97 date = now + offset
98 day_of_month = int(date.pretty("%d"))
99 month = int(date.pretty("%m"))
100 day_of_week = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ][int(date.pretty("%w"))]
101
102 # Loop through issues
103 for issue in issues:
104 # Check if the issue is "due" for the current date
105 if (issue.has_key("days_of_month") and \
106 not day_of_month in issue["days_of_month"]) or \
107 (issue.has_key("days_of_week") and \
108 not day_of_week in issue["days_of_week"]) or \
109 (issue.has_key("months") and \
110 not month in issue["months"]):
111 continue
112 if (not issue.has_key("days_of_week")) and \
113 (not issue.has_key("days_of_month")) and \
114 (not issue.has_key("months")):
115 print "Warning! Issue has no dates: "+issue["title"]
116 continue
117
118 # Check whether we already added enough of it
119 if not issue.has_key("add_max"):
120 issue["add_max"] = 1
121 if issue["add_max"] == 0:
122 continue
123 issue["add_max"] -= 1
124
125 # Check if the issue is already existing
126 if db.issue.filter(None, { "autogen_id": ("%s %d" % (date.pretty("%Y-%m-%d"), hash(issue["title"])))}):
127 continue
128
129 # Add message
130 if issue.has_key("message"):
131 msg = [db.msg.create(
132 author = db.user.lookup("admin"),
133 date = Date("."),
134 content = issue["message"]) ]
135 else:
136 msg = None
137
138 # Add issue
139 revives = date + Interval("%dd" % issue["revives"])
140 if revives > Date("."):
141 db.issue.create( \
142 title = issue["title"],
143 status = db.status.lookup("waiting"),
144 revives = revives,
145 due_date = date,
146 messages = msg,
147 priority = db.priority.lookup(issue["priority"]),
148 keyword = [ db.keyword.lookup(issue["keyword"])],
149 assignedto = db.user.lookup("nikratio"),
150 autogen_id=("%s %d" % (date.pretty("%Y-%m-%d"), hash(issue["title"]))))
151 else:
152 db.issue.create( \
153 title = issue["title"],
154 status = db.status.lookup("needs attention"),
155 due_date = date,
156 messages = msg,
157 priority = db.priority.lookup(issue["priority"]),
158 keyword = [ db.keyword.lookup(issue["keyword"])],
159 assignedto = db.user.lookup("nikratio"),
160 autogen_id=("%s %d" % (date.pretty("%Y-%m-%d"), hash(issue["title"]))))
161 # End issue loop
162 # end date loop
163
164
165 db.commit()
166 db.close()
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.