# Task: determine which files need to be "p4 add'ed." from readp4marshal import runp4cmd from readp4marshal import SubtractTwoHashes import os # # num of calls to 'p4': 2 # status: tested on Darwin Mac OS X using Python 2.3 # room for optimization/improvement: add getopts call # # Copyright 2004 Perforce Corporation, Inc. All rights reserved. def appendFunction(filedict, dirname, names): for name in names: f = os.path.join(dirname, name) if os.path.isfile(f): filedict[f] = 1 #----------------------------------------------------------- # first call to P4: 'p4 client -o' # Note that it's easier to get the client root dir from # the 'client spec'. #----------------------------------------------------------- [cl_spec] = runp4cmd("p4 -G client -o") cl_name = cl_spec['Client'] cl_root = cl_spec['Root'] #----------------------------------------------------------- # second call to P4: 'p4 fstat //myclient/...' #----------------------------------------------------------- ret = runp4cmd("p4 -G fstat //%s/..." % cl_name) # # at this point, we create two hashes/dicts to hold # the filenames: # allFilesPerforce - from "p4 fstat //myclient/..." # allFilesPresent - from "os.path.walk(cl_root,...)" # we can use set operations for the tricky stuff, and # can use the code we have for 'difflabel' to do it. # allFilesPerforce = {} for r in ret: if r.has_key('headAction') and r['headAction'] != 'delete': allFilesPerforce[r['clientFile']] = 1 allFilesPresent = {} os.path.walk(cl_root, appendFunction, allFilesPresent) [onlyInPerforce,onlyOnDisk,inBoth] = SubtractTwoHashes(allFilesPerforce, allFilesPresent) print "List of files present in workspace, but unknown to Perforce:" for f in onlyOnDisk: print f print "List of files known to Perforce, but not (yet) synced to workspace:" for f in onlyInPerforce: print f