]> snippets.scripts.mit.edu Git - Scripts/git/.git/blob - TracZephyrPlugin/ZephyrPlugin.py
In TracZephyrPlugin: use subprocess instead of os.popen.
[Scripts/git/.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("\n".join(textwrap.wrap(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'], ticket['summary'], ticket['description'][:255])
23                 self.zwrite(ticket.id, message)
24         
25         def ticket_changed(self, ticket, comment, author, old_values):
26                 if old_values.has_key('status'):
27                         if ticket['status'] == 'closed':
28                                 message = "%s closed ticket as %s\n(%s)" % (author, ticket['resolution'], ticket['summary'])
29                         else:
30                                 message = "%s set status to %s\n(%s)" % (author, ticket['status'], ticket['summary'])
31                 else:
32                         message = "%s updated this ticket\n(%s)" % (author, ticket['summary'])
33                 self.zwrite(ticket.id, message)
34         
35         def ticket_deleted(self, ticket):
36                 pass