]> andersk Git - zcommit.git/blobdiff - zcommit.py
Test add of a bunch of files
[zcommit.git] / zcommit.py
index 15a223640c693a193245c5a5c0e2a9c2f4d78fa3..e56aedb259d864b1b0c8446910d382e264652005 100755 (executable)
@@ -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.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)
 
@@ -65,20 +72,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' % '\n  '.join(c['added']))
+                    if c.get('removed'):
+                        actions.append('Removed: %s\n' % '\n  '.join(c['removed']))
+                    if c.get('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'],
-                            'added' :  '\n'.join(c['added'])}
-                    msg = """%(name)s <%(email)s>
-%(message)s
-%(timestamp)s
+                            'actions' : '--\n'.join(actions)}
+                    
+                    msg = """%(name)s <%(email)s> (%(timestamp)s)
+> %(message)s
 --
-%(added)s""" % info
-                    zephyr(opts['class'], inst, zsig, msg)
+%(actions)s""" % info
+                    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'
This page took 0.570057 seconds and 4 git commands to generate.