I recently wrote a custom tool to diff CryEngine layer files in P4, and was surprised how simple it was. What follows is a quick tutorial on adding custom python tools to Perforce.
Start by heading over to Tools>Manage Custom Tools… Then click ‘New’:
You can pass a lot of information to an external tool, here is a detailed rundown. As you see above, we pass the client spec (local) file name (%f) to a python script, let’s create a new script called ‘custom_tool.py’:
import sys from PyQt4 import QtGui class custom_tool(QtGui.QMessageBox): def __init__(self, parent=None): QtGui.QMessageBox.__init__(self) self.setDetailedText(str(sys.argv)) self.show() if __name__ == "__main__": app = QtGui.QApplication(sys.argv) theTool = custom_tool() theTool.show() sys.exit(app.exec_())
What this does is simply spits out the sys.argv in a way you can see it. So now you can feed any file you right click in Perforce into a python script:
If you would like to actually do something with a file or revision on the server and are passing the %F flag to get the depot file path, you then need to use p4 print to redirect the file contents (non-binary) to a local file:
p4.run_print('-q', '-o', depotFile, localFile)