Mercurial > p > roundup > code
annotate detectors/newitemcopy.py @ 5852:44b6a79f4e70 maint-1.6
pyme no longer exists at pypi. Try using the git repo of record
so we can run the tests on this year old tree. Right after this
release in mid 2018, pyme was depricated on 2018-10-16.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 21 Aug 2019 20:59:32 -0400 |
| parents | 198b6e810c67 |
| children | 23b8e6067f7c |
| rev | line source |
|---|---|
|
5115
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
1 from roundup import hyperdb, roundupdb |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
2 from roundup.mailer import Mailer |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
3 |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
4 |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
5 def indentChangeNoteValue(text): |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
6 # copied from roundupdb.IssueClass.indentChangeNoteValue() |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
7 lines = text.rstrip('\n').split('\n') |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
8 lines = [ ' '+line for line in lines ] |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
9 return '\n'.join(lines) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
10 |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
11 def generateCreateNote(db, cl, nodeid): |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
12 # copied from roundupdb.IssueClass.generateCreateNote() |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
13 cn = cl.classname |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
14 props = cl.getprops(protected=0) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
15 |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
16 # list the values |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
17 m = [] |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
18 prop_items = props.items() |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
19 prop_items.sort() |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
20 for propname, prop in prop_items: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
21 value = cl.get(nodeid, propname, None) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
22 # skip boring entries |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
23 if not value: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
24 continue |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
25 if isinstance(prop, hyperdb.Link): |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
26 link = db.classes[prop.classname] |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
27 if value: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
28 key = link.labelprop(default_to_id=1) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
29 if key: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
30 value = link.get(value, key) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
31 else: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
32 value = '' |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
33 elif isinstance(prop, hyperdb.Multilink): |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
34 if value is None: value = [] |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
35 l = [] |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
36 link = db.classes[prop.classname] |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
37 key = link.labelprop(default_to_id=1) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
38 if key: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
39 value = [link.get(entry, key) for entry in value] |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
40 value.sort() |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
41 value = ', '.join(value) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
42 else: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
43 value = str(value) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
44 if '\n' in value: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
45 value = '\n'+indentChangeNoteValue(value) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
46 m.append('%s: %s'%(propname, value)) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
47 m.insert(0, '----------') |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
48 m.insert(0, '') |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
49 return '\n'.join(m) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
50 |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
51 def newitemcopy(db, cl, nodeid, oldvalues): |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
52 ''' Copy a message about new items to the dispatcher address. |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
53 ''' |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
54 try: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
55 create_note = cl.generateCreateNote(nodeid) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
56 except AttributeError: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
57 create_note = generateCreateNote(db, cl, nodeid) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
58 |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
59 try: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
60 dispatcher_email = getattr(db.config, 'DISPATCHER_EMAIL') |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
61 except AttributeError: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
62 return |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
63 |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
64 try: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
65 msgids = cl.get(nodeid, 'messages') |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
66 except KeyError: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
67 msgids = None |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
68 |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
69 if msgids: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
70 # send a copy to the dispatcher |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
71 for msgid in msgids: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
72 try: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
73 cl.send_message(nodeid, msgid, create_note, [dispatcher_email]) |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5115
diff
changeset
|
74 except roundupdb.MessageSendError as message: |
|
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5115
diff
changeset
|
75 raise roundupdb.DetectorError(message) |
|
5115
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
76 else: |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
77 mailer = Mailer(db.config) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
78 subject = 'New %s%s' % (cl.classname, nodeid) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
79 mailer.standard_message([dispatcher_email], subject, create_note) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
80 |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
81 def init(db): |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
82 for classname in db.getclasses(): |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
83 cl = db.getclass(classname) |
|
ec06bd6ea156
issue2550767: Add newitemcopy.py detector to notify users of new
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
84 cl.react('create', newitemcopy) |
