问题描述
我有以下代码.我正在尝试从 Perforce 检出两个文件并将它们放入更改列表中.但是 run_add
不会检出文件.我在 Perforce 中唯一看到的是一个空的更改列表,其中没有文件.
I have following piece of code. I'm trying to check out two files from Perforce and put them in a changelist. But run_add
does not check the files out. The only thing I see in Perforce is a empty changelist with no files in it.
""" Checks out files from workspace using P4"""
files = ['analyse-location.cfg', 'CMakeLists.txt']
p4 = P4()
# Connect and disconnect
if (p4.connected()):
p4.disconnect()
p4.port = portp4
p4.user = usernameP4
p4.password = passwordP4
p4.client = clientP4
try:
p4.connect()
if p4.connected():
change = p4.fetch_change()
change['Description'] = "Auto"
change['Files'] = []
changeList = p4.save_change(change)[0].split()[1]
for items in files:
abs_path = script_dir + "\\" + items
p4.run_add("-c", changeList, items)
print("Adding file "+ abs_path + " to "+ changeList)
# Done! Disconnect!
p4.disconnect()
except P4Exception:
print("Something went wrong in P4 connection. The errors are: ")
for e in p4.errors:
print(e)
p4.disconnect()
然而,当我改为 p4.run("edit", items)
时,它会将文件放在默认的更改列表中.它真的让我很紧张.我不知道我这样做是错误的.更改列表也已创建.我在 Windows 上使用 python 3.7 32 位
However, when I have instead p4.run("edit", items)
it puts the files in the default changelist.It really gets on my nervs. I don't know I am doing that is wrong. The changes list created as well. I use python 3.7 32 bits on Windows
推荐答案
我将我的问题更改为以下问题,并且成功了.
I changed my question to following and it worked.
p4.port = portp4
p4.user = usernameP4
p4.password = passwordP4
p4.client = clientP4
try:
p4.connect()
if p4.connected():
change = p4.fetch_change()
change['Description'] = "Auto"
change['Files'] = []
changeList = p4.save_change(change)[0].split()[1]
for items in files:
abs_path = script_dir + "\\" + items
output = p4.run_edit("-c", changeList, items)
print("Adding file "+ abs_path + " to "+ changeList)
if output:
print(output)
if p4.errors:
print(p4.errors)
if p4.warnings:
print(p4.warnings)
p4.disconnect()
except P4Exception:
print("Something went wrong in P4 connection. The errors are: ")
for e in p4.errors:
print(e)
p4.disconnect()
感谢@Sam Stafford 的提示.现在它就像一个魅力.关键是将 p4.run_add("-c", changelist, items)
改为 p4.run_edit("-c", changelist, items)
Thanks to @Sam Stafford for his hint. Now it works just like a charm. The key was to change p4.run_add("-c", changelist, items)
to p4.run_edit("-c", changelist, items)
这篇关于P4Python 不会在 Perforce 中检出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!