]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - TracZephyrPlugin/ZephyrPlugin.py
In TracZephyrPlugin: use subprocess instead of os.popen.
[Scripts/git/.git] / TracZephyrPlugin / ZephyrPlugin.py
CommitLineData
76e24b1f
EB
1from trac.core import *
2from trac.ticket import ITicketChangeListener
6ae9f02e 3import subprocess
76e24b1f
EB
4import textwrap
5
6class ZephyrPlugin(Component):
7 implements(ITicketChangeListener)
8
9 def zwrite(self, id, message):
10 zclass = self.config.get('ZephyrPlugin', 'class')
11 if zclass == '':
12 return
6ae9f02e
EB
13 p = subprocess.Popen(['zwrite', '-q', '-l', '-d',
14 '-c', zclass,
15 '-i', 'trac-#%s' % id],
16 stdin=subprocess.PIPE)
17 p.stdin.write("\n".join(textwrap.wrap(message)).encode('utf-8', 'replace'))
18 p.stdin.close()
19 p.wait()
76e24b1f
EB
20
21 def ticket_created(self, ticket):
22 message = "%s filed a new ticket:\n%s\n\n%s" % (ticket['reporter'], ticket['summary'], ticket['description'][:255])
23 self.zwrite(ticket.id, message)
24
25 def ticket_changed(self, ticket, comment, author, old_values):
26 if old_values.has_key('status'):
27 if ticket['status'] == 'closed':
28 message = "%s closed ticket as %s\n(%s)" % (author, ticket['resolution'], ticket['summary'])
29 else:
30 message = "%s set status to %s\n(%s)" % (author, ticket['status'], ticket['summary'])
31 else:
32 message = "%s updated this ticket\n(%s)" % (author, ticket['summary'])
33 self.zwrite(ticket.id, message)
34
35 def ticket_deleted(self, ticket):
36 pass