1 from trac.core import *
2 from trac.ticket import ITicketChangeListener
7 class ZephyrPlugin(Component):
8 implements(ITicketChangeListener)
10 def zwrite(self, id, message):
11 zclass = self.config.get('ZephyrPlugin', 'class')
14 command = shlex.split(self.config.get('ZephyrPlugin', 'command'))
16 command = ['zwrite', '-q', '-l', '-d']
17 p = subprocess.Popen(command +
19 '-i', 'trac-#%s' % id],
20 stdin=subprocess.PIPE)
21 p.stdin.write(message.replace('@', '@@').encode('utf-8', 'replace'))
25 def format_text(self, text):
26 lines = textwrap.fill(text).split('\n')
28 lines = lines[:5] + [u'[…]']
29 return '\n'.join(lines)
31 def ticket_created(self, ticket):
32 message = "%s filed a new ticket:\n%s\n\n%s" % (ticket['reporter'],
34 self.format_text(ticket['description']))
35 self.zwrite(ticket.id, message)
37 def ticket_changed(self, ticket, comment, author, old_values):
38 if old_values.has_key('status'):
39 if ticket['status'] == 'closed':
40 message = "%s closed ticket as %s\n(%s)" % (author, ticket['resolution'], ticket['summary'])
42 message = "%s set status to %s\n(%s)" % (author, ticket['status'], ticket['summary'])
44 message = "%s updated this ticket\n(%s)" % (author, ticket['summary'])
45 self.zwrite(ticket.id, message)
47 def ticket_deleted(self, ticket):