X-Git-Url: http://andersk.mit.edu/gitweb/zcommit.git/blobdiff_plain/f0fbfde03c2a0c8acdaf300de178e5966756f57b..2a04f5aef731fea2f368374ff3a0db318bc58a9b:/zcommit.py diff --git a/zcommit.py b/zcommit.py index cc9fec1..6756e3e 100755 --- a/zcommit.py +++ b/zcommit.py @@ -4,10 +4,13 @@ import cherrypy from flup.server.fcgi import WSGIServer import logging import json +import os import subprocess import sys import traceback +HERE = os.path.abspath(os.path.dirname(__file__)) +ZWRITE = os.path.join(HERE, 'bin', 'zsend') LOG_FILENAME = 'logs/zcommit.log' # Set up a specific logger with our desired output level @@ -18,15 +21,19 @@ logger.setLevel(logging.DEBUG) handler = logging.FileHandler(LOG_FILENAME) logger.addHandler(handler) -def zephyr(klass, instance, zsig, msg): +def zephyr(sender, klass, instance, zsig, msg): # TODO: spoof the sender logger.info("""About to send zephyr: +sender: %(sender)s class: %(klass)s instance: %(instance)s zsig: %(zsig)s -msg: %(msg)s""" % {'klass' : klass, 'instance' : instance, - 'zsig' : zsig, 'msg' : msg}) - cmd = ['zwrite', '-c', klass, '-i', instance, +msg: %(msg)s""" % {'sender' : sender, + 'klass' : klass, + 'instance' : instance, + 'zsig' : zsig, + 'msg' : msg}) + cmd = [ZWRITE, '-S', sender, '-c', klass, '-i', instance, '-s', zsig, '-d', '-m', msg] subprocess.check_call(cmd) @@ -34,7 +41,36 @@ class Application(object): @cherrypy.expose def index(self): logger.debug('Hello world app reached') - return 'Hello world!' + return """ +

Welcome to zcommit.

+ +

zcommit allows you to send zephyr notifications by sending an HTTP +POST request to a URL. Currently zcommit supports POST-backs from +github. If you would like it to support another form of POST-back, +please let us know (zcommit@mit.edu).

+ +

URL structure

+ +The URL you post to is structured as follows: +http://zcommit.mit.edu/$type/$key1/$value1/$key2/$value2/.... +So for example, the URL +http://zcommit.mit.edu/github/class/zcommit/instance/commit +is parsed as having type github, class zcommit, and +instance commit. Using this information, zcommit figures out +how to form a useful message which is then sends as a zephyr. + +

Github

+ +Set your POST-back URL to +http://zcommit.mit.edu/github/class/$classname, followed by +any of the following optional key/value parameters: + + +""" class Github(object): @cherrypy.expose @@ -65,30 +101,30 @@ class Application(object): zsig = payload['ref'] if 'zsig' in opts: zsig = '%s: %s' % (opts['zsig'], zsig) + sender = opts.get('sender', 'daemon.zcommit') logger.debug('Set zsig') for c in reversed(payload['commits']): inst = opts.get('instance', c['id'][:8]) actions = [] if c.get('added'): - actions.append('Added: %s\n' % ', '.join(c['added'])) + actions.append('Added: %s\n' % '\n '.join(c['added'])) if c.get('removed'): - actions.append('Removed: %s\n' % ', '.join(c['removed'])) + actions.append('Removed: %s\n' % '\n '.join(c['removed'])) if c.get('modified'): - actions.append('Modified: %s\n' % ', '.join(c['modified'])) + actions.append('Modified: %s\n' % '\n '.join(c['modified'])) if not actions: actions.append('Something weird happened... could not figure out what action to take') info = {'name' : c['author']['name'], 'email' : c['author']['email'], 'message' : c['message'], 'timestamp' : c['timestamp'], - 'actions' : '\n--\n'.join(actions)} + 'actions' : '--\n'.join(actions)} - msg = """%(name)s <%(email)s> -%(message)s -%(timestamp)s + msg = """%(name)s <%(email)s> (%(timestamp)s) +> %(message)s -- %(actions)s""" % info - zephyr(opts['class'], inst, zsig, msg) + zephyr(sender, opts['class'], inst, zsig, msg) msg = 'Thanks for posting!' else: msg = ('If you had sent a POST request to this URL, would have sent'