So last time I more introduced you to the idea of triggers, here’s a more complex example. This worked on my db, but if you have branching you would need to check each returned file against the branch you are submitting to.
Check if The File is Already in the Depot
This is a trigger that checks the hash digest of the incoming file against that of the server. This way you can see if the user is checking in a file that already exists.
import sys from P4 import P4, P4Exception p4 = P4() describe =  try: p4.user = "admin" p4.password = "admin" p4.port = "1666" p4.connect() lst = sys.argv stat = p4.run('fstat', ('-Ol','//depot/...@'+ str(lst))) hash = stat['digest'] fname = stat['depotFile'] m = p4.run('fstat', ('-Ol','-F', ('digest = ' + str(hash)),'//depot/...')) existing =  for file in m: if file['depotFile'] != fname: existing.append(file) if existing != : print '\n\nFILE EXISTS IN DEPOT!!' print 'YOUR FILE: ' + (fname.split('/')[-1]) for file in existing: print 'EXACTLY MATCHES: ' + file['depotFile'] print 'P4 DIGEST: ' + hash print 'SOLUTION: Contact your lead if you believe this message was generated in error.' sys.exit(1) except Exception, e: print "Error: %s" % (e) sys.exit(1) p4.disconnect() sys.exit(0)
Then your trigger line looks like this:
Triggers: dupeCheck change-submit //depot/... "python X:/projects/2010/p4/dupe_trigger.py %user% %changelist%"
This is what the user will see when they try to check in: