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的信息。
示例代码如下:
workspace对象中包含的信息见下图:
[img]http://dl.iteye.com/upload/attachment/292990/b63fdc89-1759-3569-9df8-f37bbcbed467.png[/img]
[color=red]如何同步最新代码?[/color]
连接好worspace以后调用run_sync()。
示例代码如下:
[color=red]如何获取最新同步下来的文件名?[/color]
同步下来的文件信息都保存在函数run_sync()的返回值里,可以通过遍历改返回值获取文件名等信息。示例代码如下:
[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]
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]