4 from flup.server.fcgi import WSGIServer
8 def zephyr(klass, instance, zsig, msg):
9 # TODO: spoof the sender
10 cmd = ['zwrite', '-c', klass, '-i', instance,
11 '-s', zsig, '-d', '-m', msg]
12 subprocess.check_call(cmd)
14 class Application(object):
20 def default(self, *args, **kwargs):
25 def default(self, *args, **query):
28 raise cherrypy.HTTPError(400, 'Invalid submission URL')
29 for i in xrange(0, len(args), 2):
30 opts[args[i]] = args[i + 1]
32 if 'class' not in opts:
33 raise cherrypy.HTTPError(400, 'Must specify a zephyr class name')
35 if cherrypy.request.method == 'POST':
36 payload = json.loads(query['payload'])
40 zsig = '%s: %s' % (opts['zsig'], zsig)
44 for c in reversed(payload['commits']):
45 inst = opts.get('instance', c['id'][:8])
46 c['added_as_str'] = '\n'.join(c['added'])
47 msg = """%(name)s <%(email)s>
52 zephyr(opts['class'], inst, zsig, msg)
54 msg = ('If you had sent a POST request to this URL, would have sent'
55 ' a zepyhr to -c %s' % opts['class'])
61 app = cherrypy.tree.mount(Application(), '/zcommit')
62 cherrypy.server.unsubscribe()
63 cherrypy.engine.start()
65 WSGIServer(app, environ={'SCRIPT_NAME' : '/zcommit'}).run()
67 cherrypy.engine.stop()
69 if __name__ == '__main__':