# This progam is used to automatically version # client specifications. # # A new client may be created (p4w.py) or an existing # client spec can be edited. # # Create the directory stucture specified by 'clientpath' # first before running script for the first time. # # Gerry Thompson Python Class Perforce Software 2002 # Version 1.0 # This imports my p4s.py and p4w.py modules. import marshal, os, string, p4s, p4w p4path = 'p4' # Path to p4 executable clientpath = '//depot/versions/clients/' # Path to client files in depot admin = 'gerry+client@perforce.com' # My 'From' address for email to = 'gerry@perforce.com' # My email address p4 = p4path def checkclient(aclient): oneline = os.popen(p4 + ' -s files '+ clientpath + aclient, 'r').readline() check = string.split(oneline, ) if len(check) == 0: print 'An error has occured in p4c.py' else: if check[0] == 'error:': # The client name is a new client. os.popen(p4 + ' add ' + clientpath + aclient) else: os.popen(p4 + ' sync '+ clientpath + aclient) os.popen(p4 + ' edit '+ clientpath + aclient) # The client file already exits. def makefile(client): checkclient(client) newline = [] for aline in os.popen(p4 + ' client -o '+ client, 'r').readlines(): if aline[0] != '#': if aline[0] != '\n': newline.append(aline) alist = os.popen(p4 + ' -G fstat ' + clientpath + client ,'rb') dict = marshal.load(alist) # for key in dict.keys(): These two lines will # print "%s: %s" % (key, dict[key]) list keys and values. path = dict['clientFile'] open(path, 'w').writelines(newline) p4s.tryit(admin, to) def getclient(clientname): if clientname == '': clientname = p4w.getinfo() else: os.popen(p4 + ' client '+ clientname ,'r') # This opens the #client spec for editing. makefile(clientname) def neworedit(): nclient = '' print 'Type in a client name to edit or return for a new client. '+ '\n' nclient = raw_input() getclient(nclient) if __name__ == '__main__': neworedit()