P4python is the python interface to Perforce API, it helps to do Perforce operations through python. i will share basic operations: sync / submmit / add / delete
you need to know some details about Perforce cmd, please find it in the below link:
you need to use below codes for Perforce connect, login and disconnect.
def P4Connection(src,dst): try: p4.connect() p4.run_login() operation(src,dst) except P4Exception: for e in p4.errors: # Display errors print e finally: p4.disconnect()
you can define operations in the operation() function. i will show sync/submmit/add/delete files
def sync(file): ''' User can sync single file, all the files in the same directory, the files with same suffix,or the files with same version.
it depends on the rule of file #single file://depot/Projects/a.txt #all files: //depot/Projects/... #same suffix: //depot/Projects/*.pptx ''' p4.run_sync(file)
def submmit(): #open=p4.run_open(srcFile) ###you may need to open the file manually change = p4.fetch_change() change['Description']='Auto submit' p4.run_submit(change)
def add(file): ''' #User can add single file, or all the files in the same folder addFile=r'D:PerforcedepotProjectsa.txt' addFolder=r'D:PerforcedepotProjects...' ''' p4.run_add(file) #user need to change the description and submmit the changelist manually after add new files. submmit()
def delete(file): ''' #User can delete single file, or all the files in the same folder delFile='//depot/Projects/a.txt' delFolder='//depot/Projects/...' ''' p4.run_delete(file) #User need to submmit the changelist manually like Add operation submmit()
Hope that it can be helpful for Perforce operations.