Skip to content

Commit 4a1b207

Browse files
committed
issue2550767: Add newitemcopy.py detector to notify users of new
items. Added to detectors directory and a README.txt generated to describe the purpose of the directory. It also says the detectors are provided on an as-is basis and may not work. Detector by W. Trevor King (wking).
1 parent f002f46 commit 4a1b207

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

detectors/README.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
This directory has some detector examples that you can use to get
2+
ideas on implementing your own detectors.
3+
4+
These are provides on an as-is basis. When they were added, they
5+
worked for somebody and were considered a useful example.
6+
7+
The roundup team will attempt to keep them up to date with major
8+
changes as they happen, but there are no guarantees that these will
9+
work out of the box. If you find them out of date and have patches to
10+
make them work against newer versions of roundup, please open an issue
11+
at:
12+
13+
http://issues.roundup-tracker.org
14+
15+
The current inventory is:
16+
17+
creator_resolution.py - only allow the creator of the issue to resolve it
18+
19+
emailauditor.py - Rename .eml files (from email multi-part bodies) to
20+
.mht so they can be downloaded/viewed in Internet Explorer.
21+
22+
irker.py - communicate with irkerd to allow roundtup to send announcements
23+
to an IRC channel.
24+
25+
newissuecopy.py - notify a team email address (hardcoded in the script)
26+
when a new issue arrives.
27+
28+
newitemcopy.py - email the DISPATCHER address when new issues, users,
29+
keywords etc. are created. Kind of an expanded version
30+
of newissuecopy.

detectors/newitemcopy.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from roundup import hyperdb, roundupdb
2+
from roundup.mailer import Mailer
3+
4+
5+
def indentChangeNoteValue(text):
6+
# copied from roundupdb.IssueClass.indentChangeNoteValue()
7+
lines = text.rstrip('\n').split('\n')
8+
lines = [ ' '+line for line in lines ]
9+
return '\n'.join(lines)
10+
11+
def generateCreateNote(db, cl, nodeid):
12+
# copied from roundupdb.IssueClass.generateCreateNote()
13+
cn = cl.classname
14+
props = cl.getprops(protected=0)
15+
16+
# list the values
17+
m = []
18+
prop_items = props.items()
19+
prop_items.sort()
20+
for propname, prop in prop_items:
21+
value = cl.get(nodeid, propname, None)
22+
# skip boring entries
23+
if not value:
24+
continue
25+
if isinstance(prop, hyperdb.Link):
26+
link = db.classes[prop.classname]
27+
if value:
28+
key = link.labelprop(default_to_id=1)
29+
if key:
30+
value = link.get(value, key)
31+
else:
32+
value = ''
33+
elif isinstance(prop, hyperdb.Multilink):
34+
if value is None: value = []
35+
l = []
36+
link = db.classes[prop.classname]
37+
key = link.labelprop(default_to_id=1)
38+
if key:
39+
value = [link.get(entry, key) for entry in value]
40+
value.sort()
41+
value = ', '.join(value)
42+
else:
43+
value = str(value)
44+
if '\n' in value:
45+
value = '\n'+indentChangeNoteValue(value)
46+
m.append('%s: %s'%(propname, value))
47+
m.insert(0, '----------')
48+
m.insert(0, '')
49+
return '\n'.join(m)
50+
51+
def newitemcopy(db, cl, nodeid, oldvalues):
52+
''' Copy a message about new items to the dispatcher address.
53+
'''
54+
try:
55+
create_note = cl.generateCreateNote(nodeid)
56+
except AttributeError:
57+
create_note = generateCreateNote(db, cl, nodeid)
58+
59+
try:
60+
dispatcher_email = getattr(db.config, 'DISPATCHER_EMAIL')
61+
except AttributeError:
62+
return
63+
64+
try:
65+
msgids = cl.get(nodeid, 'messages')
66+
except KeyError:
67+
msgids = None
68+
69+
if msgids:
70+
# send a copy to the dispatcher
71+
for msgid in msgids:
72+
try:
73+
cl.send_message(nodeid, msgid, create_note, [dispatcher_email])
74+
except roundupdb.MessageSendError, message:
75+
raise roundupdb.DetectorError, message
76+
else:
77+
mailer = Mailer(db.config)
78+
subject = 'New %s%s' % (cl.classname, nodeid)
79+
mailer.standard_message([dispatcher_email], subject, create_note)
80+
81+
def init(db):
82+
for classname in db.getclasses():
83+
cl = db.getclass(classname)
84+
cl.react('create', newitemcopy)

0 commit comments

Comments
 (0)