# 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
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 4312 | Jeff Bowles |
Adding a number of example scripts that show how to get to Perforce data for a variety of scripting languages and variety of simple tasks. Note that Perl/Python/Ruby (and variants) are included, but shell/batch/DCL/applescript are not. (Am trying to stick with somewhat-portable approaches, to make comparisons easier.) Each program is written in the following languages/configurations: 1. Perl, calling "p4 -Ztag" for data 2. Perl, calling Tony Smith's "P4Perl" module 3. Python, calling "p4 -G" for data 4. Ruby, calling "p4 -R" for data 5. Ruby, calling Tony Smith's "P4Ruby" module The programs do the following: a. compare client specs to users (find old clients) b. compare two labels c. determine which client specs use compression. d. determine which files need to be "p4 add'ed." e. output list of 'opened' files, using local pathnames. |