Skip to content

Commit 25e9ed6

Browse files
author
Richard Jones
committed
Here's a cron-job reminder script...
...that we're going to be using here at ekit. Might be useful for other people. Could use some work making it more general and easier to customise.
1 parent 8b3c1ac commit 25e9ed6

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

scripts/roundup-reminder

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#! /usr/bin/env python
2+
# Copyright (c) 2002 ekit.com Inc (http://www.ekit-inc.com/)
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in
12+
# all copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
# SOFTWARE.
21+
22+
# $Id: roundup-reminder,v 1.1 2002-04-15 06:37:31 richard Exp $
23+
24+
'''
25+
Simple script that emails all users of a tracker with the issues that
26+
are currently assigned to them.
27+
28+
TODO: introduce some structure ;)
29+
TODO: possibly make this more general and configurable...
30+
31+
Note: The instance that this script was designed for has a modified schema!
32+
You will want to modify this script to customise it for your own schema!
33+
'''
34+
35+
import cStringIO, MimeWriter, smtplib
36+
from roundup import instance, date
37+
38+
# open the instance
39+
if len(sys.argv) != 2:
40+
print 'You need to specify an instance home dir'
41+
instance_home = sys.argv[1]
42+
instance = instance.open(instance_home)
43+
db = instance.open('admin')
44+
45+
resolved_id = db.status.lookup('resolved')
46+
47+
# loop through all the users
48+
for user_id in db.user.list():
49+
# make sure we care aboue this user
50+
name = db.user.get(user_id, 'realname')
51+
if name is None:
52+
name = db.user.get(user_id, 'username')
53+
address = db.user.get(user_id, 'address')
54+
if address is None:
55+
continue
56+
57+
# extract this user's issues
58+
l = []
59+
for issue_id in db.issue.find(assignedto=user_id):
60+
if db.issue.get(issue_id, 'status') == resolved_id: continue
61+
timeliness_id = db.issue.get(issue_id, 'timeliness')
62+
if timeliness_id:
63+
timeliness = db.timeliness.get(timeliness_id, 'name')
64+
else:
65+
timeliness = '~~~'
66+
l.append((timeliness, db.issue.get(issue_id, 'creation'), issue_id))
67+
68+
# sort the issues by timeliness and creation date
69+
l.sort()
70+
if not l:
71+
continue
72+
73+
# generate the email message
74+
message = cStringIO.StringIO()
75+
writer = MimeWriter.MimeWriter(message)
76+
writer.addheader('Subject', 'Your active %s issues'%db.config.INSTANCE_NAME)
77+
writer.addheader('To', address)
78+
writer.addheader('From', '%s <%s>'%(db.config.INSTANCE_NAME,
79+
db.config.ADMIN_EMAIL))
80+
writer.addheader('Reply-To', '%s <%s>'%(db.config.INSTANCE_NAME,
81+
db.config.ADMIN_EMAIL))
82+
writer.addheader('MIME-Version', '1.0')
83+
writer.addheader('X-Roundup-Name', db.config.INSTANCE_NAME)
84+
85+
# start the multipart
86+
part = writer.startmultipartbody('alternative')
87+
part = writer.nextpart()
88+
body = part.startbody('text/plain')
89+
90+
# do the plain text bit
91+
print >>body, 'Created ID Urgency Title'
92+
print >>body, '='*75
93+
# '2 months 213 immediate cc_daemon barfage
94+
for timeliness, creation_date, issue_id in l:
95+
# pretty creation
96+
creation = (date.Date('.') - creation_date).pretty()
97+
if creation is None:
98+
creation = creation_date.pretty()
99+
100+
if not timeliness: timeliness = ''
101+
title = db.issue.get(issue_id, 'title')
102+
if len(title) > 52: title = title[:48] + ' ...'
103+
print >>body, '%-11s %-4s %-9s %-52s'%(creation, issue_id,
104+
timeliness, title)
105+
106+
# now the HTML one
107+
part = writer.nextpart()
108+
body = part.startbody('text/html')
109+
colours = {
110+
'immediate': ' bgcolor="#ffcdcd"',
111+
'day': ' bgcolor="#ffdecd"',
112+
'week': ' bgcolor="#ffeecd"',
113+
'month': ' bgcolor="#ffffcd"',
114+
'whenever': ' bgcolor="#ffffff"',
115+
}
116+
print >>body, '''<table border>
117+
<tr><th>Created</th> <th>ID</th> <th>Urgency</th> <th>Title</th></tr>
118+
'''
119+
for timeliness, creation_date, issue_id in l:
120+
creation = (date.Date('.') - creation_date).pretty()
121+
if creation is None:
122+
creation = creation_date.pretty()
123+
if not timeliness_id: timeliness_id = ' '
124+
title = db.issue.get(issue_id, 'title')
125+
issue_id = '<a href="%sissue%s">%s</a>'%(db.config.ISSUE_TRACKER_WEB,
126+
issue_id, issue_id)
127+
colour = colours.get(timeliness, '')
128+
print >>body, '''<tr%s><td>%s</td><td>%s</td><td>%s</td>
129+
<td>%s</td></tr>'''%(colour, creation, issue_id, timeliness, title)
130+
print >>body, '</table>'
131+
132+
# finish of the multipart
133+
writer.lastpart()
134+
135+
# all done, send!
136+
smtp = smtplib.SMTP(db.config.MAILHOST)
137+
smtp.sendmail(db.config.ADMIN_EMAIL, address, message.getvalue())
138+
139+
#
140+
# $Log: not supported by cvs2svn $
141+
#
142+
#

0 commit comments

Comments
 (0)