]> sipb.mit.edu Git - snippets/.git/blob - TracZephyrPlugin/ZephyrPlugin.py
better URL to the web interface
[snippets/.git] / TracZephyrPlugin / ZephyrPlugin.py
1 from trac.core import *
2 from trac.ticket import ITicketChangeListener
3 import os
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                 pipe = os.popen('zwrite -q -l -d -c %s -i trac-#%s' % (zclass, id), 'w')
14                 pipe.write("\n".join(textwrap.wrap(message)).encode('utf-8', 'replace'))
15                 pipe.close()
16         
17         def ticket_created(self, ticket):
18                 message = "%s filed a new ticket:\n%s\n\n%s" % (ticket['reporter'], ticket['summary'], ticket['description'][:255])
19                 self.zwrite(ticket.id, message)
20         
21         def ticket_changed(self, ticket, comment, author, old_values):
22                 if old_values.has_key('status'):
23                         if ticket['status'] == 'closed':
24                                 message = "%s closed ticket as %s\n(%s)" % (author, ticket['resolution'], ticket['summary'])
25                         else:
26                                 message = "%s set status to %s\n(%s)" % (author, ticket['status'], ticket['summary'])
27                 else:
28                         message = "%s updated this ticket\n(%s)" % (author, ticket['summary'])
29                 self.zwrite(ticket.id, message)
30         
31         def ticket_deleted(self, ticket):
32                 pass