# This progam is used to automatically submit files # from a default changelist. # An email module is called to send email when submit completes. # The email module is named submit_mail.py # Gerry Thompson Python Class Perforce Software 2002 # Version 1.0 import os, string p4path = 'p4' # Path to p4 executable. p4 = p4path def filesopen(): opened = 1 single = os.popen(p4 + ' -s opened -c default','r').readline() # If -s is not used no stderr output is captured by python and # 'result' will be an empty list. # 'File(s) not opened on this client.' is converted to stdout by # the -s flag and prepended with 'error:'. result = string.split(single, ) if result[0] == 'error:': opened = 0 print 'There are no open files in the default changelist to submit!' return opened def submit(user, client, server): newchange = [] for changeline in os.popen(p4 + ' change -o ', 'r').readlines(): if string.count(changeline, "") > 0: changeline = ' Submit agent for user "'+user+'" using client "' + \ client+'" to Perforce server '+server+'.' newchange.append(changeline) os.popen(p4 + ' submit -i ', 'w').writelines(newchange) def autosubmit(): for aline in os.popen(p4 + ' info','r').readlines(): if string.count(aline, "User name") > 0: auser = string.strip(string.split(aline, 'User name: ')[-1]) if string.count(aline, "Client name") > 0: aclient = string.strip(string.split(aline, 'Client name: ')[-1]) if string.count(aline, "Server address") > 0: aserver = string.strip(string.split(aline, 'Server address: ')[-1]) submit(auser, aclient, aserver) return auser, aclient, aserver def tryit (from_user, to_user): if filesopen(): myuser, myclient, myserver = autosubmit() from submit_mail import sendmail sendmail (from_user, to_user, myuser, myclient, myserver)