#!/usr/local/bin/python """A Python version of the Perforce "p4" client. This uses the Python type P4Client, which is a wrapper for the Perforce ClientApi object. It includes the "ClientUser" class, which is a Python version of the default ClientUser from Perforce. Copyright 1999, Mike Meyer. All Rights Reserved See the comment in the source for redistribution permission. """ # License: # This file and any derivatives or translations of it may be freely # copied and redistributed so long as: # 1) This license and copyright notice are not changed. # 2) Any fixes or enhancements are reported back to either the # author (mwm@phone.net). # and any of: # a) The source is redistributed with it. # b) The source is compiled unmodified, and instructions for finding # the original source are included. # c) The source is made available by some other means. import sys, os, string class ClientUser: """Sample user interface class for use with the P4Client class. This classes methods are invoked by P4Client object to communicate with the user.""" debug = 0 def OutputError(self, output): "Process the text of an error message." if self.debug: print "Python: OutputError" sys.stderr.write(output) def HandleError(self, output, severity): "Process an error event" if self.debug: print "Python: HandleError; severity", severity self.OutputError(output) def InputData(self): "Returns input data." if self.debug: print "Python: InputData" return sys.stdin.read() def OutputInfo(self, data, level): "Process output data, with level info." if self.debug: print "Python: OutputInfo; level", level level = string.atoi(level) while level: print "...", level = level - 1 print data def OutputBinary(self, output): "Process binary output data" if self.debug: print "Python: OutputBinary" sys.stdout.write(output) def OutputText(self, output): "Process text output data" if self.debug: print "Python: OutputText" sys.stdout.write(output) def OutputStat(self, dict): "Process dictionary of file status info" text = "otherOpen" test = len(text) if self.debug: print "Python: OutputStat" for key, value in dict.items(): if len(key) > test and key[:test] == text: self.OutputInfo("%s %s" % (key, value), '2') else: self.OutputInfo("%s %s" % (key, value), '1') def Prompt(self, msg): "Returns results of prompting with msg" if self.debug: print "Python: Prompt" return raw_input(msg) def ErrorPause(self, buf): "Display an error message and wait for user to respond." if self.debug: print "Python: ErrorPause" self.OutputError(buf) raw_input('Hit return to continue...') def Edit(self, file): "Process an edit request." if self.debug: print "Python: Edit - ", file if os.environ.has_key("P4EDITOR"): editor = os.environ["P4EDITOR"] elif os.environ.has_key("EDITOR"): editor = os.environ["EDITOR"] else: editor = "vi" # If you don't say, you deserve what you get os.system("%s %s" % (editor, file)) def Diff(self, file1, file2, doPage, flags): "Process a diff request." if os.environ.has_key("P4DIFF"): diff = os.environ["P4DIFF"] elif os.environ.has_key("DIFF"): diff = os.environ["DIFF"] else: raise ValueError, \ "No diff program specified with $P4DIFF or $DIFF." if not doPage: pager = 0 else: if os.environ.has_key("P4PAGER"): pager = os.environ["P4pager"] elif os.environ.has_key("pager"): pager = os.environ["pager"] else: pager = 0 if pager: os.system("%s %s %s %s | %s" % (diff, flags, file1, file2, pager)) else: os.system("%s %s %s %s" % (diff, flags, file1, file2)) def Merge(self, base, leg1, leg2, result): "Process a merge request." if os.environ.has_key("P4MERGE"): merger = os.environ["P4MERGE"] elif os.environ.has_key("MERGE"): merger = os.environ["MERGE"] else: raise ValueError, \ "No merge program specified with $P4MERGE or $MERGE." os.system("%s %s %s %s %s" % (merger, base, leg1, leg2, result)) def Help(self, help): "Process help text." if self.debug: print "Python: Help" for line in help: print line if __name__ == "__main__": from P4Client import P4Client ui = ClientUser() ui.debug = 0 p4 = P4Client(ui) p4.Init() p4.SetArgv(sys.argv[2:]) p4.Run(sys.argv[1]) p4.Final()
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 5750 | Robert Cowham | New branch | ||
//guest/robert_cowham/perforce/API/python/main/utils/p4cmd.py | |||||
#1 | 4766 | Robert Cowham |
Rather better documentation (and license and changelog). Reorganised dirs. Added .zip file and windows binary installer. |