#!/bin/env python # MODIFY BELOW vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv NOTIFY = ( # Repo, path, to_emails, from_email (r'^/home/svnaccount/svn$', r'^digital/', ['billyray@example.com'], 'bobray@example.com' ), ) SMTP_PASSFILE = '/home/bobray/.sentp' SMTP_ADR = 'mail.example.com' SMTP_ACCOUNT = 'bobray@example.com' TEMP_DIR = '/tmp' DEBUG = True # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ END MODIFY # LEAVE THE REST ALONE # UNLESS YOU KNOW WHAT YOUR DOING import smtplib import os import re def sendmail(fromaddr,toaddrs,subject,inmsg): msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n" % (fromaddr, ", ".join(toaddrs), subject)) msg += inmsg f = open(SMTP_PASSFILE) server = smtplib.SMTP(SMTP_ADR) server.login(SMTP_ACCOUNT,f.readline()) f.close() if DEBUG: server.set_debuglevel(1) server.sendmail(fromaddr, toaddrs, msg) server.quit() def getdirs(rev,repo): tmpfile = "%s/svndir%s" % (TEMP_DIR, rev) os.system("touch %s" % tmpfile) cmd = "svnlook dirs-changed -r%s '%s' > '%s'" % (rev,repo,tmpfile) os.system(cmd) if DEBUG: print "getdirs() => %s" %cmd dirs = [] f = open(tmpfile) for dir in f.read().split("\n"): if dir != '': dirs.append(dir) f.close() os.system("rm '%s'"%tmpfile) if DEBUG: print "DIRS: %s" % dirs return dirs def getinfo(what, rev, repo): out = "" tmpfile = "%s/svn%s" % (TEMP_DIR, rev) os.system("touch '%s'" % tmpfile) os.system("svn %s -r%s 'file://%s' > '%s'" % (what, rev, repo, tmpfile)) f = open(tmpfile) out += f.read() f.close() os.system("rm '%s'"%tmpfile) if DEBUG: print "getinfo(%s,%s,%s) = %s" % (what,rev,repo,out) return out import sys repo = sys.argv[1] rev = sys.argv[2] dirs = getdirs(rev,repo) for entry in NOTIFY: if DEBUG: print entry log = "Commit #%s\n" % rev dif = "\n\nDETAILS\n" for dir in dirs: if DEBUG: print "looking at %s with %s\n" % (dir,entry[1]) if re.findall(entry[1], dir) != []: if DEBUG: print "found %s\n" % dir log += getinfo("log -v",rev,"%s/%s"% (repo,dir)) dif += getinfo("diff",str(int(rev)-1),"%s/%s"% (repo,dir)) if dif != "Changes:\n": sendmail(entry[3], entry[2], "Subversion Commit #%s %s" % (rev,repo),log+dif)