[p4python] Catching none p4 files

Martinsson, Christian Christian.Martinsson at dice.se
Fri Dec 30 01:56:23 PST 2011

Hi Peter

No I have files that is not in the p4 data base, just local files that I might want to add later on.

I came up with this today, it's not nice but it works.

def categorizeFiles( filePathList ):
                """ Take a list of files and check if they are in p4, local or none existing.
                Return a dictionary with following keys: p4Files, localFiles and noneExistingFiles
                # Initialize return variables
                p4Files = []
                localFiles = []
                noneExistingFiles = []

                # Initialize p4 class
                p4 = P4()
                                # Setup connection to p4

                                # Check if we manage to connection to p4
                                if p4.connected():

                                                # Convert string user to an list
                                                if type(filePathList).__name__ == 'str':
                                                                filePathList = [filePathList]

                                                for filePath in filePathList:
                                                                # Check for none existing files
                                                                if not os.path.exists( filePath ):
                                                                                noneExistingFiles.append( filePath )
                                                                                # Try to get p4 information from file, if it fails it's a local file
                                                                                                p4.run('fstat', filePath)
                                                                                                p4Files.append( filePath )
                                                                                except P4Exception:
                                                                                                localFiles.append( filePath )

                                                sys.exit("P4 faild to connect to p4 server on port: "+ p4.port +" client: "+ p4.client +" user: "+ p4.user )

                                p4.disconnect()                                #Make sure we always disconnect from p4 server

                return {'p4Files':p4Files, 'localFiles':localFiles, 'noneExistingFiles':noneExistingFiles}


From: Pete Thacker [mailto:pete at ccpgames.com]
Sent: den 29 december 2011 19:43
To: Martinsson, Christian
Subject: RE: Catching none p4 files


By added, do you mean opened for add but not yet submitted? If that is the case, just check the action and if it's 'add', do a pass.

for i in p4.run("fstat", "//depot/games/shared_tools/python/27/python.exe"):
                if i['headAction'] != 'add':
                                # do something really important
                                print i


From: p4python-bounces at perforce.com<mailto:p4python-bounces at perforce.com> [mailto:p4python-bounces at perforce.com]<mailto:[mailto:p4python-bounces at perforce.com]> On Behalf Of Martinsson, Christian
Sent: Thursday, December 29, 2011 10:38 AM
To: p4python at perforce.com<mailto:p4python at perforce.com>
Subject: [p4python] Catching none p4 files

Hi everyone,

I have a list of files that I want to check fstat on, but some of the might not be added to p4, is there a way to catch this files so I can remove them from the list.

Problem right now is that fstat crashes (without error) when a none p4 files is in the list.

Also the -R options seems to crash without error, is this not supported in P4Python?
Ex:  p4.run("fstat","-Ro", "filepath")

And when using -T option with otherOpen it only returns the number of other users not the users.
Ex:  p4.run("fstat","-T otherOpen", "filepath")

Christian Martinsson
Technical Animator

Tel +46 8 658 78 00
Fax +46 8 658 78 99
Cell +46 73 6417107
Christian.Martinsson at dice.se<mailto:Christian.Martinsson at dice.se>

An EA company

EA Digital Illusions CE AB
Katarinavägen 15
P.O. Box 20068
SE-104 60 Stockholm, Sweden

Corporate Registration Number: 556710-6520

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://maillist.perforce.com/pipermail/p4python/attachments/20111230/df691a6d/attachment-0002.html>

More information about the p4python mailing list