#!/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(my, output): "Process the text of an error message." if my.debug: print "Python: OutputError" sys.stderr.write(output) def HandleError(my, output, severity): "Process an error event" if my.debug: print "Python: HandleError; severity", severity my.OutputError(output) def InputData(my): "Returns input data." if my.debug: print "Python: InputData" return sys.stdin.read() def OutputInfo(my, data, level): "Process output data, with level info." if my.debug: print "Python: OutputInfo; level", level level = string.atoi(level) while level: print "...", level = level - 1 print data def OutputBinary(my, output): "Process binary output data" if my.debug: print "Python: OutputBinary" sys.stdout.write(output) def OutputText(my, output): "Process text output data" if my.debug: print "Python: OutputText" sys.stdout.write(output) def OutputStat(my, dict): "Process dictionary of file status info" text = "otherOpen" test = len(text) if my.debug: print "Python: OutputStat" for key, value in dict.items(): if len(key) > test and key[:test] == text: my.OutputInfo('2', "%s %s" % (key, value)) else: my.OutputInfo('1', "%s %s" % (key, value)) def Prompt(my, msg): "Returns results of prompting with msg" if my.debug: print "Python: Prompt" return raw_input(msg) def ErrorPause(my, buf): "Display an error message and wait for user to respond." if my.debug: print "Python: ErrorPause" my.OutputError(buf) raw_input('Hit return to continue...') def Edit(my, file): "Process an edit request." if my.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(my, 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(my, 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(my, help): "Process help text." if my.debug: print "Python: Help" for line in help: print line if __name__ == "__main__": from P4Client import P4Client ui = ClientUser() ui.debug = 1 p4 = P4Client(ui) p4.Init() p4.SetArgv(sys.argv[2:]) p4.Run(sys.argv[1]) p4.Final()
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 135 | Mike Meyer |
Changed the P4Clientmodule::OutputInfo to swap the argument order. This allows the same routine to method OutputInfo and OutputText if the level argument is made optional. |
||
#1 | 129 | Mike Meyer | Initial public version. |