changeset 4f0171b20369 in bugs.tryton.org:default
details: https://hg.tryton.org/bugs.tryton.org?cmd=changeset;node=4f0171b20369
description:
Update reminder script to roundup 2.0.0
diffstat:
reminder-assigned.py | 178 ++++++++++++++++++-----------------------
reminder.py | 217 ---------------------------------------------------
2 files changed, 77 insertions(+), 318 deletions(-)
diffs (479 lines):
diff -r b0c142110794 -r 4f0171b20369 reminder-assigned.py
--- a/reminder-assigned.py Thu Oct 29 15:40:47 2020 +0100
+++ b/reminder-assigned.py Sun Nov 01 10:15:22 2020 +0100
@@ -20,19 +20,20 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
-# $Id$
+'''
+Simple script that emails all users of a tracker with the issues that
+are currently assigned to them.
-'''
-Simple script that emails a static email address with the issues that
-are currently assigned.
+TODO: introduce some structure ;)
+TODO: possibly make this more general and configurable...
'''
-import sys, io, smtplib
-from email.mime.text import MIMEText
-from email.mime.base import MIMEBase
+from __future__ import print_function
+import sys
from email.mime.multipart import MIMEMultipart
+from email.utils import make_msgid
from roundup import instance, date
-from roundup.mailer import SMTPConnection
+from roundup.mailer import Mailer
# open the instance
if len(sys.argv) != 2:
@@ -41,21 +42,32 @@
instance = instance.open(instance_home)
db = instance.open('admin')
-address = '[email protected]'
status_excluded = [db.status.lookup('resolved'), db.status.lookup('closed'),
db.status.lookup('invalid'), db.status.lookup('deferred'),
db.status.lookup('done-cbb')]
-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
+class Reverse:
+ """Class reversing sort order."""
+
+ def __init__(self, val):
+ self.val = val
+
+ def __lt__(self, other):
+ return other.val < self.val
+ def __le__(self, other):
+ return other.val <= self.val
+ def __eq__(self, other):
+ return other.val == self.val
+ def __ne__(self, other):
+ return other.val != self.val
+ def __gt__(self, other):
+ return other.val > self.val
+ def __ge__(self, other):
+ return other.val >= self.val
+
+def listKey(x):
+ "key for tuples such that order is positive on [0] and negative on [1]"
+ return (x[0], Reverse(x[1]))
return 0
# loop through all the users
@@ -71,135 +83,99 @@
# extract this user's issues
l = []
for issue_id in db.issue.find(assignedto=user_id):
- if (db.issue.get(issue_id, 'status') in status_excluded) :
+ if db.issue.get(issue_id, 'status') in status_excluded:
continue
- priority_id = db.issue.get(issue_id, 'priority')
- if priority_id:
- order = db.priority.get(priority_id, 'order')
- else:
- order = sys.maxsize
+ 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(listCompare)
- # if not l:
- # continue
-
- if l == []:
+ l.sort(key=listKey)
+ if not l:
continue
# generate the email message
- message = MIMEMultipart()
- message['Subject'] = 'Assigned %s requests' % db.config.TRACKER_NAME
- message['To'] = address
- message['FROM'] = '%s <%s>' % (db.config.TRACKER_NAME,
db.config.ADMIN_EMAIL)
- message['Reply-To'] = '%s <%s>'%(db.config.TRACKER_NAME,
db.config.ADMIN_EMAIL)
+ mailer = Mailer(db.config)
+ message = MIMEMultipart('alternative')
+ mailer.set_message_attributes(
+ message,
+ [address],
+ 'Your active %s issues'%db.config.TRACKER_NAME)
+ message['Reply-To'] = '%s <%s>'%(db.config.TRACKER_NAME,
+ db.config.ADMIN_EMAIL)
+ message['Message-Id'] = make_msgid()
message['Auto-Submitted'] = 'auto-generated'
- message['X-Roundup-Name'] = db.config.TRACKER_NAME
-
- #message = cStringIO.StringIO()
- #writer = MimeWriter.MimeWriter(message)
- #writer.addheader('Subject', 'Un-assigned %s
requests'%db.config.TRACKER_NAME)
- #writer.addheader('To', address)
- #writer.addheader('From', '%s <%s>'%(db.config.TRACKER_NAME,
- # db.config.ADMIN_EMAIL))
- #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.TRACKER_NAME)
-
- # start the multipart
- inner = MIMEMultipart('alternative')
- message.attach(inner)
- part = MIMEBase('text', 'plain')
- inner.attach(part)
- body = io.StringIO()
-
- #part = writer.startmultipartbody('alternative')
- #part = writer.nextpart()
- #body = part.startbody('text/plain')
# do the plain text bit
- print('Created ID Activity Title', file=body)
- print('='*75, file=body)
+ text_lines = []
+ text_lines.append('Created ID Activity Title')
+ text_lines.append('='*75)
# '2 months 213 immediate cc_daemon barfage
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
- if priority:
- print(' ', db.priority.get(priority,'name'), file=body)
+ text_lines.append(' ' + db.priority.get(priority,'name'))
# pretty creation
creation = (creation_date - date.Date('.')).pretty()
- if creation is None:
- creation = creation_date.pretty()
-
activity = (activity_date - date.Date('.')).pretty()
title = db.issue.get(issue_id, 'title')
if len(title) > 42:
title = title[:38] + ' ...'
- print('%-11s %-4s %-9s %-42s'%(creation, issue_id,
- activity, title), file=body)
+ text_lines.append('%-11s %-4s %-9s %-42s'%(creation, issue_id,
+ activity, title))
# some help to finish off
- print('''
- To view or respond to any of the requests listed above, visit the URL
+ text_lines.append('''
+To view or respond to any of the issues listed above, visit the URL
- %s
+ %s
- and click on "Your Issues". Do NOT respond to this message.
- '''%db.config.TRACKER_WEB, file=body)
+and click on "My Issues". Do NOT respond to this message.
+'''%db.config.TRACKER_WEB)
+ text = '\n'.join(text_lines) + '\n'
+ part = mailer.get_text_message()
+ part.set_payload(text, part.get_charset())
+ message.attach(part)
- part.set_payload(body.getvalue().decode('UTF-8'), 'UTF-8')
# now the HTML one
- part = MIMEBase('text', 'html')
- inner.attach(part)
- body = io.StringIO()
- #part = writer.nextpart()
- #body = part.startbody('text/html')
+ html_lines = []
colours = {
- 'ASAP': ' bgcolor="#ffcdcd"',
+ 'immediate': ' bgcolor="#ffcdcd"',
'day': ' bgcolor="#ffdecd"',
'week': ' bgcolor="#ffeecd"',
'month': ' bgcolor="#ffffcd"',
'whenever': ' bgcolor="#ffffff"',
}
- print('''<p>This is an automatically generated reminder of
- assigned issues.</p>
- <p>Please consider taking action on assigned requests listed below</p>
- ''', file=body)
-
- print('''<table border>
- <tr><th>Created</th> <th>ID</th> <th>Activity</th> <th>Title</th></tr>
- ''', file=body)
+ html_lines.append('''<table border>
+<tr><th>Created</th> <th>ID</th> <th>Activity</th> <th>Title</th></tr>
+''')
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
- if priority:
-
print('<tr><td>-></td><td>-></td><td>-></td><td><b>%s</b></td></tr>'%db.priority.get(priority,'name'),
file=body)
+ old_priority = priority
+
html_lines.append('<tr><td>-></td><td>-></td><td>-></td><td><b>%s</b></td></tr>'%db.priority.get(priority,'name'))
creation = (creation_date - date.Date('.')).pretty()
- if creation is None:
- creation = creation_date.pretty()
title = db.issue.get(issue_id, 'title')
issue_id = '<a href="%sissue%s">%s</a>'%(db.config.TRACKER_WEB,
issue_id, issue_id)
activity = (activity_date - date.Date('.')).pretty()
- print('''<tr><td>%s</td><td>%s</td><td>%s</td>
- <td>%s</td></tr>'''%(creation, issue_id, activity, title), file=body)
- print('</table>', file=body)
+ html_lines.append('''<tr><td>%s</td><td>%s</td><td>%s</td>
+ <td>%s</td></tr>'''%(creation, issue_id, activity, title))
+ html_lines.append('</table>')
- part.set_payload(body.getvalue().decode('UTF-8'), 'UTF-8')
-
- # finish of the multipart
- #writer.lastpart()
+ html_lines.append('''<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>''')
+ html = '\n'.join(html_lines) + '\n'
+ part = mailer.get_text_message('utf-8', 'html')
+ part.set_payload(html, part.get_charset())
+ message.attach(part)
# all done, send!
- smtp = SMTPConnection(db.config)
- smtp.sendmail(db.config.ADMIN_EMAIL, address, message.as_string())
+ mailer.smtp_send([address], message.as_string())
# vim: set filetype=python ts=4 sw=4 et si
diff -r b0c142110794 -r 4f0171b20369 reminder.py
--- a/reminder.py Thu Oct 29 15:40:47 2020 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,217 +0,0 @@
-#! /usr/bin/env python
-# Copyright (c) 2002 ekit.com Inc (http://www.ekit-inc.com/)
-# Copyright (c) 2010-2016 Cedric Krier
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-# $Id$
-
-'''
-Simple script that emails a static email address with the issues that
-are currently un-assigned.
-'''
-
-import sys, io, smtplib
-from email.mime.text import MIMEText
-from email.mime.base import MIMEBase
-from email.mime.multipart import MIMEMultipart
-from roundup import instance, date
-from roundup.mailer import SMTPConnection
-
-# open the instance
-if len(sys.argv) != 2:
- print('You need to specify an instance home dir')
-instance_home = sys.argv[1]
-instance = instance.open(instance_home)
-db = instance.open('admin')
-
-address = '[email protected]'
-status_excluded = [db.status.lookup('resolved'), db.status.lookup('closed'),
- db.status.lookup('invalid'), db.status.lookup('deferred'),
- db.status.lookup('done-cbb')]
-priorities_excluded = [db.priority.lookup('wish'),
db.priority.lookup('feature')]
-types_excluded = [db.type.lookup('behavior'), db.type.lookup('feature
request'),
- db.type.lookup('performance'), db.type.lookup('security')]
-
-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
- name = db.user.get(user_id, 'realname')
- if name is None:
- name = db.user.get(user_id, 'username')
- address = db.user.get(user_id, 'address')
- if address is None:
- continue
-'''
-user_id=None
-# extract this user's issues
-l = []
-for issue_id in db.issue.find(assignedto=user_id):
- if (db.issue.get(issue_id, 'status') in status_excluded) :
- continue
- if (db.issue.get(issue_id, 'priority') in priorities_excluded):
- continue
- if (db.issue.get(issue_id, 'type') in types_excluded):
- continue
- priority_id = db.issue.get(issue_id, 'priority')
- if priority_id:
- order = db.priority.get(priority_id, 'order')
- else:
- order = sys.maxsize
- 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(listCompare)
-# if not l:
-# continue
-
-if l == []:
- print("No Un-assigned requests therefore no reason to email.")
- sys.exit()
-
-# generate the email message
-message = MIMEMultipart()
-message['Subject'] = 'Un-assigned %s requests' % db.config.TRACKER_NAME
-message['To'] = address
-message['FROM'] = '%s <%s>' % (db.config.TRACKER_NAME, db.config.ADMIN_EMAIL)
-message['Reply-To'] = '%s <%s>'%(db.config.TRACKER_NAME, db.config.ADMIN_EMAIL)
-message['Auto-Submitted'] = 'auto-generated'
-message['X-Roundup-Name'] = db.config.TRACKER_NAME
-
-#message = cStringIO.StringIO()
-#writer = MimeWriter.MimeWriter(message)
-#writer.addheader('Subject', 'Un-assigned %s requests'%db.config.TRACKER_NAME)
-#writer.addheader('To', address)
-#writer.addheader('From', '%s <%s>'%(db.config.TRACKER_NAME,
-# db.config.ADMIN_EMAIL))
-#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.TRACKER_NAME)
-
-# start the multipart
-inner = MIMEMultipart('alternative')
-message.attach(inner)
-part = MIMEBase('text', 'plain')
-inner.attach(part)
-body = io.StringIO()
-
-#part = writer.startmultipartbody('alternative')
-#part = writer.nextpart()
-#body = part.startbody('text/plain')
-
-# do the plain text bit
-print('Created ID Activity Title', file=body)
-print('='*75, file=body)
-# '2 months 213 immediate cc_daemon barfage
-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
- if priority:
- print(' ', db.priority.get(priority,'name'), file=body)
- # pretty creation
- creation = (creation_date - date.Date('.')).pretty()
- if creation is None:
- creation = creation_date.pretty()
-
- activity = (activity_date - date.Date('.')).pretty()
- title = db.issue.get(issue_id, 'title')
- if len(title) > 42:
- title = title[:38] + ' ...'
- print('%-11s %-4s %-9s %-42s'%(creation, issue_id,
- activity, title), file=body)
-
-# some help to finish off
-print('''
-To view or respond to any of the requests listed above, visit the URL
-
- %s
-
-and click on "Show Unassigned". Do NOT respond to this message.
-'''%db.config.TRACKER_WEB, file=body)
-
-part.set_payload(body.getvalue().decode('UTF-8'), 'UTF-8')
-
-# now the HTML one
-part = MIMEBase('text', 'html')
-inner.attach(part)
-body = io.StringIO()
-#part = writer.nextpart()
-#body = part.startbody('text/html')
-colours = {
- 'ASAP': ' bgcolor="#ffcdcd"',
- 'day': ' bgcolor="#ffdecd"',
- 'week': ' bgcolor="#ffeecd"',
- 'month': ' bgcolor="#ffffcd"',
- 'whenever': ' bgcolor="#ffffff"',
-}
-print('''<p>This is an automatically generated reminder of
-un-assigned issues.</p>
-<p>Please consider taking ownership of un-assigned requests listed below.
When you do,
-<br>be sure to update the tracker's assigned to field. To assign requests
listed below,
-<br>click on the Request ID link in this email, login to the tracker, and
change
-<br>the Assigned To field to yourself.</p>
-''', file=body)
-
-print('''<table border>
-<tr><th>Created</th> <th>ID</th> <th>Activity</th> <th>Title</th></tr>
-''', file=body)
-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
- if priority:
-
print('<tr><td>-></td><td>-></td><td>-></td><td><b>%s</b></td></tr>'%db.priority.get(priority,'name'),
file=body)
- creation = (creation_date - date.Date('.')).pretty()
- if creation is None:
- creation = creation_date.pretty()
- title = db.issue.get(issue_id, 'title')
- issue_id = '<a href="%sissue%s">%s</a>'%(db.config.TRACKER_WEB,
- issue_id, issue_id)
- activity = (activity_date - date.Date('.')).pretty()
- print('''<tr><td>%s</td><td>%s</td><td>%s</td>
-<td>%s</td></tr>'''%(creation, issue_id, activity, title), file=body)
-print('</table>', file=body)
-
-part.set_payload(body.getvalue().decode('UTF-8'), 'UTF-8')
-
-# finish of the multipart
-#writer.lastpart()
-
-# all done, send!
-smtp = SMTPConnection(db.config)
-smtp.sendmail(db.config.ADMIN_EMAIL, address, message.as_string())
-
-# vim: set filetype=python ts=4 sw=4 et si