Javier Somoza | 17 Feb 2006 13:48
Picon

Sending CVS change mail to developers


    Im using this (adding it to the master.cfg) to send a mail to the developers about a commit on the cvs.
    Surely this will not be the best way (i've just done it and havent got time to enhance it) but if someone finds it useful...


import sys, os, os.path, string, smtplib, MimeWriter, mimetypes, base64, tempfile, StringIO

sender = "cvs-change <at> buildbot"
changeRecipients = []
changeRecipients.append("developer1 <at> domain,")
changeRecipients.append("developer2 <at> domain,")
changeRecipients.append("developer3 <at> domain")

def addHtml(mime, infile):
    part = mime.nextpart()
    part.addheader("Content-Transfer-Encoding", "7bit")
    outfile = part.startbody("text/html", [("charset","us-ascii")])
    while 1:
        s = infile.read(BLK_SIZE)
        if not s: break
        outfile.write(s)

def createCVSMail(message):
    msgfile = open("/tmp/cvs-commit.eml","w")
    mime = MimeWriter.MimeWriter(msgfile)
    mime.addheader("To", string.join(changeRecipients))
    mime.addheader("From", sender)
    mime.addheader("Subject", "CVS change")
    mime.addheader("MIME-Version", "1.0")
    mime.startmultipartbody("mixed")
    f = StringIO.StringIO(message)
    addHtml(mime, f)
    f.close
    mime.lastpart()
    msgfile.flush()
    msgfile.close()

def manageChange (changes):
        server = smtplib.SMTP('192.168.1.4')
        createCVSMail(changes.asHTML())
        msg = open('/tmp/cvs-commit.eml', 'r').read()
        server.sendmail(sender, changeRecipients, msg)
        os.remove("/tmp/cvs-commit.eml")
        server.quit()


Gmane