]> sipb.mit.edu Git - snippets/.git/blob - TracZephyrPlugin/ZephyrPlugin.py
Add back usage information for kdo.
[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         p = subprocess.Popen(['zwrite', '-q', '-l', '-d',
14                               '-c', zclass,
15                               '-i', 'trac-#%s' % id],
16                              stdin=subprocess.PIPE)
17         p.stdin.write(message.encode('utf-8', 'replace'))
18         p.stdin.close()
19         p.wait()
20     
21     def ticket_created(self, ticket):
22         message = "%s filed a new ticket:\n%s\n\n%s" % (ticket['reporter'],
23                                                         ticket['summary'],
24                                                         textwrap.fill(ticket['description'][:255]))
25         self.zwrite(ticket.id, message)
26     
27     def ticket_changed(self, ticket, comment, author, old_values):
28         if old_values.has_key('status'):
29             if ticket['status'] == 'closed':
30                 message = "%s closed ticket as %s\n(%s)" % (author, ticket['resolution'], ticket['summary'])
31             else:
32                 message = "%s set status to %s\n(%s)" % (author, ticket['status'], ticket['summary'])
33         else:
34             message = "%s updated this ticket\n(%s)" % (author, ticket['summary'])
35         self.zwrite(ticket.id, message)
36     
37     def ticket_deleted(self, ticket):
38         pass