Code

test that announcement.txt is pure ASCII, required at least up to
[roundup.git] / scripts / roundup-reminder
index f5940f9e083fdc172cd67876d156560d245219b1..38ed9c34b2874624122396dfb7646d261cff6832 100755 (executable)
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
-# $Id: roundup-reminder,v 1.1 2002-04-15 06:37:31 richard Exp $
-
 '''
 Simple script that emails all users of a tracker with the issues that
 are currently assigned to them.
 
 TODO: introduce some structure ;)
 TODO: possibly make this more general and configurable...
-
-Note: The instance that this script was designed for has a modified schema!
-      You will want to modify this script to customise it for your own schema!
 '''
 
-import cStringIO, MimeWriter, smtplib
+import sys, cStringIO, MimeWriter, smtplib
 from roundup import instance, date
+from roundup.mailer import SMTPConnection
 
 # open the instance
 if len(sys.argv) != 2:
@@ -44,6 +40,18 @@ db = instance.open('admin')
 
 resolved_id = db.status.lookup('resolved')
 
+def listCompare(x, y):
+    "compare two tuples such that order is positive on [0] and negative on [1]"
+    if x[0] < y[0]:
+        return -1
+    if x[0] > y[0]:
+        return 1
+    if x[1] > y[1]:
+        return -1
+    if x[1] < y[1]:
+        return 1
+    return 0
+
 # loop through all the users
 for user_id in db.user.list():
     # make sure we care aboue this user
@@ -57,30 +65,28 @@ for user_id in db.user.list():
     # extract this user's issues
     l = []
     for issue_id in db.issue.find(assignedto=user_id):
-        if db.issue.get(issue_id, 'status') == resolved_id: continue
-        timeliness_id = db.issue.get(issue_id, 'timeliness')
-        if timeliness_id:
-            timeliness = db.timeliness.get(timeliness_id, 'name')
-        else:
-            timeliness = '~~~'
-        l.append((timeliness, db.issue.get(issue_id, 'creation'), issue_id))
+        if db.issue.get(issue_id, 'status') == resolved_id:
+            continue
+        order = db.priority.get(db.issue.get(issue_id, 'priority'), 'order')
+        l.append((order, db.issue.get(issue_id, 'activity'),
+            db.issue.get(issue_id, 'creation'), issue_id))
 
     # sort the issues by timeliness and creation date
-    l.sort()
+    l.sort(listCompare)
     if not l:
         continue
 
     # generate the email message
     message = cStringIO.StringIO()
     writer = MimeWriter.MimeWriter(message)
-    writer.addheader('Subject', 'Your active %s issues'%db.config.INSTANCE_NAME)
+    writer.addheader('Subject', 'Your active %s issues'%db.config.TRACKER_NAME)
     writer.addheader('To', address)
-    writer.addheader('From', '%s <%s>'%(db.config.INSTANCE_NAME,
+    writer.addheader('From', '%s <%s>'%(db.config.TRACKER_NAME,
         db.config.ADMIN_EMAIL))
-    writer.addheader('Reply-To', '%s <%s>'%(db.config.INSTANCE_NAME,
+    writer.addheader('Reply-To', '%s <%s>'%(db.config.TRACKER_NAME,
         db.config.ADMIN_EMAIL))
     writer.addheader('MIME-Version', '1.0')
-    writer.addheader('X-Roundup-Name', db.config.INSTANCE_NAME)
+    writer.addheader('X-Roundup-Name', db.config.TRACKER_NAME)
 
     # start the multipart
     part = writer.startmultipartbody('alternative')
@@ -88,20 +94,35 @@ for user_id in db.user.list():
     body = part.startbody('text/plain')
     
     # do the plain text bit
-    print >>body, 'Created     ID   Urgency   Title'
+    print >>body, 'Created     ID   Activity  Title'
     print >>body, '='*75
     #             '2 months    213  immediate cc_daemon barfage
-    for timeliness, creation_date, issue_id in l:
+    old_priority = None
+    for priority_order, activity_date, creation_date, issue_id in l:
+        priority = db.issue.get(issue_id, 'priority')
+        if (priority != old_priority):
+            old_priority = priority
+            print >>body, '    ', db.priority.get(priority,'name')
         # pretty creation
-        creation = (date.Date('.') - creation_date).pretty()
+        creation = (creation_date - date.Date('.')).pretty()
         if creation is None:
             creation = creation_date.pretty()
-
-        if not timeliness: timeliness = ''
+        activity = (activity_date - date.Date('.')).pretty()
         title = db.issue.get(issue_id, 'title')
-        if len(title) > 52: title = title[:48] + ' ...'
-        print >>body, '%-11s %-4s %-9s %-52s'%(creation, issue_id,
-            timeliness, title)
+        if len(title) > 42:
+            title = title[:38] + ' ...'
+        print >>body, '%-11s %-4s %-9s %-42s'%(creation, issue_id,
+            activity, title)
+
+    # some help to finish off
+    print >>body, '''
+To view or respond to any of the issues listed above, visit the URL
+
+   %s
+
+and click on "My Issues". Do NOT respond to this message.
+'''%db.config.TRACKER_WEB
+
 
     # now the HTML one
     part = writer.nextpart()
@@ -114,29 +135,34 @@ for user_id in db.user.list():
         'whenever': ' bgcolor="#ffffff"',
     }
     print >>body, '''<table border>
-<tr><th>Created</th> <th>ID</th> <th>Urgency</th> <th>Title</th></tr>
+<tr><th>Created</th> <th>ID</th> <th>Activity</th> <th>Title</th></tr>
 '''
-    for timeliness, creation_date, issue_id in l:
+    old_priority = None
+    for priority_order, activity_date, creation_date, issue_id in l:
+        priority = db.issue.get(issue_id,'priority')
+        if (priority != old_priority):
+           old_priority = priority
+           print >>body, '<tr><td>-></td><td>-></td><td>-></td><td><b>%s</b></td></tr>'%db.priority.get(priority,'name')
         creation = (date.Date('.') - creation_date).pretty()
         if creation is None:
-            creation = creation_date.pretty()
-        if not timeliness_id: timeliness_id = ' '
+            creation = (creation_date - date.Date('.')).pretty()
         title = db.issue.get(issue_id, 'title')
-        issue_id = '<a href="%sissue%s">%s</a>'%(db.config.ISSUE_TRACKER_WEB,
+        issue_id = '<a href="%sissue%s">%s</a>'%(db.config.TRACKER_WEB,
             issue_id, issue_id)
-        colour = colours.get(timeliness, '')
-        print >>body, '''<tr%s><td>%s</td><td>%s</td><td>%s</td>
-    <td>%s</td></tr>'''%(colour, creation, issue_id, timeliness, title)
+        activity = (activity_date - date.Date('.')).pretty()
+        print >>body, '''<tr><td>%s</td><td>%s</td><td>%s</td>
+    <td>%s</td></tr>'''%(creation, issue_id, activity, title)
     print >>body, '</table>'
 
+    print >>body, '''<p>To view or respond to any of the issues listed
+        above, simply click on the issue ID. Do <b>not</b> respond to
+        this message.</p>'''
+
     # finish of the multipart
     writer.lastpart()
 
     # all done, send!
-    smtp = smtplib.SMTP(db.config.MAILHOST)
+    smtp = SMTPConnection(db.config)
     smtp.sendmail(db.config.ADMIN_EMAIL, address, message.getvalue())
 
-#
-# $Log: not supported by cvs2svn $
-#
-#
+# vim: set filetype=python ts=4 sw=4 et si