]> sipb.mit.edu Git - snippets/.git/blob - TracZephyrPlugin/ZephyrPlugin.py
f011a8b3f0662082c7e917c88b89d738d6e21f0b
[snippets/.git] / TracZephyrPlugin / ZephyrPlugin.py
1 from trac.core import *
2 from trac.ticket import ITicketChangeListener
3 import subprocess
4 import textwrap
5
6 class ZephyrPlugin(Component):
7     implements(ITicketChangeListener)
8     
9     def zwrite(self, id, message):
10         zclass = self.config.get('ZephyrPlugin', 'class')
11         if zclass == '':
12             return
13         command = self.config.get('ZephyrPlugin', 'command').split(' ')
14         if not command:
15             command = ['zwrite', '-q', '-l', '-d']
16         p = subprocess.Popen(command +
17                              ['-c', zclass,
18                               '-i', 'trac-#%s' % id],
19                              stdin=subprocess.PIPE)
20         p.stdin.write(message.encode('utf-8', 'replace'))
21         p.stdin.close()
22         p.wait()
23     
24     def ticket_created(self, ticket):
25         message = "%s filed a new ticket:\n%s\n\n%s" % (ticket['reporter'],
26                                                         ticket['summary'],
27                                                         textwrap.fill(ticket['description'][:255]))
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