#!/usr/bin/env python #################################################### # findPList.py # # Written by Chris Stillson # # This code is in the Public Domain. Pretend there is # a fancy legal disclaimer here limiting liability. # # You probably want to put an entry in a crontab # to have this script run every night. # import os import string import smtplib gMailhost = "mail" # PUT THE NAME OF YOUR MAILHOST HERE gAdmin = "root" # ADMINISTRATION EMAIL ADDRESS gMailHead = """ ** PENDING CHANGELIST NOTIFICATION\r \r This is an automatically generated email to inform you that you have\r pending changelists in Perforce which have not been fully\r submitted. If you don't fully submit the changelists, your changes may\r be lost. Normally all this requires is a "p4 resolve -af" followed by\r "p4 submit -c ". If the pending changelist has no\r files, you can delete it using "p4 change -d "\r \r\n \r\n However, sometimes there are more complicated problems. If you have\r trouble resolving a pending changelist, drop an email to\r %s.\r\n """ % gAdmin # :$Id: class pList: def __init__(self): self.lines = os.popen("p4 changes -s pending").readlines() self.pendings = {} for line in self.lines: split = string.split(line) user = string.split(split[5], "@")[0] if self.pendings.has_key(user): self.pendings[user].append(split[1]) else: self.pendings[user] = [split[1]] def __len__(self): return self.pendings.len() def __getitem__(self,i): return self.pendings[i] def items(self): return self.pendings.items() def main(): pend = pList() mailport = smtplib.SMTP(gMailhost) for user,cList in pend.items(): #find email em = os.popen('p4 user -o %s | egrep "^Email:"' % user).readlines()[0] em = string.split(em)[-1] #find info about changes descriptions = ["From: %s" % gAdmin, "To: %s" % em, "Subject: pending changelists\r\n\r\n", gMailHead] for change in cList: descriptions = descriptions + os.popen("p4 describe %s" % change).readlines() #bundle it up and mail it message = string.join(descriptions, "\r\n") try: mailport.sendmail(gAdmin, [em], message) print "notified: %s" % em except: print "trouble deliverying to: %s " % em mailport.quit() if __name__ == "__main__": main()