一 p4的API支持几乎所有的常用的语言
1)查看p4 API 主页: http://www.perforce.com/perforce/loadsupp.html#api (包含下载 和 p4script.pdf)
2)支持几乎所有的语言:
Perforce C/C++ API
Perforce Java API
Perforce Perl API
Perforce Ruby API
Perforce Python API
Perforce PHP API
Perforce Objective-C API
P4COM, a COM Interface to the Perforce C++ API for Windows
二 p4python
1)安装(以windows为例)
下载和安装python2.6;(可以安装activepython)
下载和安装p4python26;(ftp://ftp.perforce.com/perforce/r09.2/bin.ntx86/p4python26.exe)
2)安装后(C:\Python26\Lib\site-packages)
文件:P4.py + P4.pyc + P4API.pyd + P4Python-2009.2-py2.6.egg-info。其中P4API.pyd为python对p4的extension模块,里面定义了 P4API.P4Adapter可惜看不到源码,P4.py 里面包含了p4 class的定义,p4class从P4API.P4Adapter继承。
3)p4.py
在p4.py中定义了
• P4
• P4Exception
• DepotFile
• Revision
• Integration
• MergeData
• Spec
其中主要的p4 class定义如下:
class P4(P4API.P4Adapter):
""" Use this class to communicate with a Perforce server
Instances of P4 will use the environment settings (including P4CONFIG)
to determine the connection parameters such as P4CLIENT and P4PORT.
This attributes can also be set separately before connecting.
To run any Perforce commands, users of this class first need to run
the connect() method.
It is good practice to disconnect() after the program is complete.
"""
# Constants useful for exception_level
# RAISE_ALL: Errors and Warnings are raised as exceptions (default)
# RAISE_ERROR: Only Errors are raised as exceptions
# RAISE_NONE: No exceptions are raised, instead False is returned
RAISE_ALL = 2
RAISE_ERROR = 1
RAISE_NONE = 0
def __init__ (self, * args, ** kwlist):
P4API.P4Adapter. __init__ (self, * args, ** kwlist)
def __del__ (self):
if self.debug > 3 :
print >> sys.stderr, " P4.__del__() "
# store the references to the created lambdas as a weakref to allow Python
# to clean up the garbage. |The lambda as a closure stores a reference to self
# which causes a circular reference problem without the weakref
def __getattr__ (self, name):
if name.startswith( " run_ " ):
cmd = name[len( " run_ " ):]
return lambda * args: self.run(cmd, * args)
elif name.startswith( " delete_ " ):
cmd = name[len( " delete_ " ):]
return lambda * args: self.run(cmd, " -d " , * args)
elif name.startswith( " fetch_ " ):
cmd = name[len( " fetch_ " ):]
return lambda * args: self.run(cmd, " -o " , * args)[0]
elif name.startswith( " save_ " ):
cmd = name[len( " save_ " ):]
return lambda * args: self. __save (cmd, * args)
elif name.startswith( " parse_ "