]> sipb.mit.edu Git - snippets/.git/commitdiff
Add my Trac zephyr plugin.
authorEvan Broder <broder@mit.edu>
Tue, 3 Feb 2009 00:41:53 +0000 (19:41 -0500)
committerEvan Broder <broder@mit.edu>
Tue, 3 Feb 2009 00:41:53 +0000 (19:41 -0500)
TracZephyrPlugin/.gitignore [new file with mode: 0644]
TracZephyrPlugin/INSTALL [new file with mode: 0644]
TracZephyrPlugin/ZephyrPlugin.py [new file with mode: 0644]
TracZephyrPlugin/setup.py [new file with mode: 0755]

diff --git a/TracZephyrPlugin/.gitignore b/TracZephyrPlugin/.gitignore
new file mode 100644 (file)
index 0000000..f07a57d
--- /dev/null
@@ -0,0 +1,4 @@
+build
+dist
+*.pyc
+*.egg-info
diff --git a/TracZephyrPlugin/INSTALL b/TracZephyrPlugin/INSTALL
new file mode 100644 (file)
index 0000000..28c6bf2
--- /dev/null
@@ -0,0 +1,14 @@
+To install the TracZephyrPlugin, first run
+
+  $ python setup.py bdist_egg
+
+then copy the .egg file in the dist/ directory into the plugins/ directory of
+your trac install.
+
+To enable the plugin, you must configure the class that zephyr updates should
+go to. To do this, add a section like the following to your trac.ini:
+
+  [ZephyrPlugin]
+  class = debathena
+
+Then be sure to restart the FastCGI processes if there are any.
diff --git a/TracZephyrPlugin/ZephyrPlugin.py b/TracZephyrPlugin/ZephyrPlugin.py
new file mode 100644 (file)
index 0000000..688749a
--- /dev/null
@@ -0,0 +1,32 @@
+from trac.core import *
+from trac.ticket import ITicketChangeListener
+import os
+import textwrap
+
+class ZephyrPlugin(Component):
+       implements(ITicketChangeListener)
+       
+       def zwrite(self, id, message):
+               zclass = self.config.get('ZephyrPlugin', 'class')
+               if zclass == '':
+                       return
+               pipe = os.popen('zwrite -q -l -d -c %s -i trac-#%s' % (zclass, id), 'w')
+               pipe.write("\n".join(textwrap.wrap(message)).encode('utf-8', 'replace'))
+               pipe.close()
+       
+       def ticket_created(self, ticket):
+               message = "%s filed a new ticket:\n%s\n\n%s" % (ticket['reporter'], ticket['summary'], ticket['description'][:255])
+               self.zwrite(ticket.id, message)
+       
+       def ticket_changed(self, ticket, comment, author, old_values):
+               if old_values.has_key('status'):
+                       if ticket['status'] == 'closed':
+                               message = "%s closed ticket as %s\n(%s)" % (author, ticket['resolution'], ticket['summary'])
+                       else:
+                               message = "%s set status to %s\n(%s)" % (author, ticket['status'], ticket['summary'])
+               else:
+                       message = "%s updated this ticket\n(%s)" % (author, ticket['summary'])
+               self.zwrite(ticket.id, message)
+       
+       def ticket_deleted(self, ticket):
+               pass
diff --git a/TracZephyrPlugin/setup.py b/TracZephyrPlugin/setup.py
new file mode 100755 (executable)
index 0000000..ef27899
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/python
+
+from setuptools import find_packages, setup
+
+setup(
+    name='TracZephyrPlugin',
+    version='1.2',
+    author='Evan Broder',
+    author_email='broder@mit.edu',
+    description='Send a zephyr when a Trac ticket is created or updated',
+    py_modules=["ZephyrPlugin"],
+    entry_points = """
+        [trac.plugins]
+        ZephyrPlugin = ZephyrPlugin
+    """,
+)