P4提供的Pytohn接口资料

Perforce的Python API的下载链接:
ftp://ftp.perforce.com/perforce/r09.2/bin.ntx86/p4python26.exe
API 文档
http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html

[color=red]如何获得workspace的信息?[/color]
通过调用P4.fetch_client()返回workspace的信息。
示例代码如下:

p4 = P4()
p4.client = 'PocketACG'
p4.connect()
# client 相当于是workspace。根据p4.client的赋值查找workspace,如果找得到则返回一
# 个workspace对象。找不到则新建一个。
client = p4.fetch_client()
p4.disconnect()

workspace对象中包含的信息见下图:
[img]http://dl.iteye.com/upload/attachment/292990/b63fdc89-1759-3569-9df8-f37bbcbed467.png[/img]
[color=red]如何同步最新代码?[/color]
连接好worspace以后调用run_sync()。
示例代码如下:
    
p4 = P4()
try:
p4.client = 'PocketACG_For_Test'
p4.user = 'yoshiyan'
p4.port = '1666'
p4.password = 'xxx0xx'
p4.exception_level = 1
p4.connect()

for syncFileInfo in p4.run_sync():
print syncFileInfo['clientFile']
except P4Exception, e:
print "Error accessing Perforce: ",e
sys.exit(1)
finally:
p4.disconnect()


[color=red]如何获取最新同步下来的文件名?[/color]
同步下来的文件信息都保存在函数run_sync()的返回值里,可以通过遍历改返回值获取文件名等信息。示例代码如下:

for syncFileInfo in p4.run_sync():
print syncFileInfo['clientFile']


[color=red]默认情况下,P4的API调用即使碰到Warning也会抛出异常,可否修改这一行为?[/color]
可以通过修改p4.exception_level来改变这一行为。
[quote]Configures the events which give rise to exceptions. The following three levels are supported:
1. disables all exception handling and makes the interface completely procedural; you are responsible for checking the p4.errors and p4.warnings arrays.
2. causes exceptions to be raised only when errors are encountered.
3. causes exceptions to be raised for both errors and warnings. This is the default.[/quote]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值