]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - TracZephyrPlugin/ZephyrPlugin.py
TracZephyrPlugin: Permit using a custom command (e.g. zcrypt)
[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):
cace67b2
EB
7 implements(ITicketChangeListener)
8
9 def zwrite(self, id, message):
10 zclass = self.config.get('ZephyrPlugin', 'class')
11 if zclass == '':
12 return
da9785cf
GT
13 command = self.config.get('ZephyrPlugin', 'command')
14 if not command:
15 command = 'zwrite'
16 p = subprocess.Popen([command, '-q', '-l', '-d',
cace67b2
EB
17 '-c', zclass,
18 '-i', 'trac-#%s' % id],
19 stdin=subprocess.PIPE)
606dbf12 20 p.stdin.write(message.encode('utf-8', 'replace'))
cace67b2
EB
21 p.stdin.close()
22 p.wait()
23
24 def ticket_created(self, ticket):
606dbf12
EB
25 message = "%s filed a new ticket:\n%s\n\n%s" % (ticket['reporter'],
26 ticket['summary'],
27 textwrap.fill(ticket['description'][:255]))
cace67b2
EB
28 self.zwrite(ticket.id, message)
29
30 def ticket_changed(self, ticket, comment, author, old_values):
31 if old_values.has_key('status'):
32 if ticket['status'] == 'closed':
33 message = "%s closed ticket as %s\n(%s)" % (author, ticket['resolution'], ticket['summary'])
34 else:
35 message = "%s set status to %s\n(%s)" % (author, ticket['status'], ticket['summary'])
36 else:
37 message = "%s updated this ticket\n(%s)" % (author, ticket['summary'])
38 self.zwrite(ticket.id, message)
39
40 def ticket_deleted(self, ticket):
41 pass