[SCM]源码管理 - perforce python的使用

本文介绍了Perforce的源码管理工具中Python API的使用,包括API支持的语言、p4python的安装步骤、核心类定义及实例应用,如p4info.py、p4sync.py和p4submit.py等,提供了详细的操作帮助。
摘要由CSDN通过智能技术生成

一 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定义如下:

import  P4API

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_ "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值