P4Python 不签出 Perforce 中的文件
P4Python does not check out the file in Perforce
我有以下一段代码。我正在尝试从 Perforce 中检出两个文件并将它们放入更改列表中。但是 run_add
没有检出文件。我在 Perforce 中看到的唯一东西是一个空的更改列表,里面没有文件。
""" 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)
时,它会将文件置于默认 changelist.It 中,这真的让我很紧张。我不知道我这样做是错的。更改列表也已创建。我在 Windows
上使用 python 3.7 32 位
您的脚本丢弃了 run_add
调用的输出。尝试改变这个:
for items in files:
abs_path = script_dir + "\" + items
p4.run_add("-c", changeList, items)
print("Adding file "+ abs_path + " to "+ changeList)
至:
for items in files:
abs_path = script_dir + "\" + items
output = p4.run_add("-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 add
命令的结果。基于 p4 edit
打开文件这一事实,我希望您会发现这样的消息:
C:\Perforce\test>p4 add foo
//stream/main/foo - can't add existing file
p4 add
和 p4 edit
命令不是同义词;一种用于添加新文件,一种用于编辑现有文件。如果您的脚本正在编辑现有文件,它应该调用 run_edit
,而不是 run_add
.
我将我的问题更改为以下并且有效。
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)
我有以下一段代码。我正在尝试从 Perforce 中检出两个文件并将它们放入更改列表中。但是 run_add
没有检出文件。我在 Perforce 中看到的唯一东西是一个空的更改列表,里面没有文件。
""" 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)
时,它会将文件置于默认 changelist.It 中,这真的让我很紧张。我不知道我这样做是错的。更改列表也已创建。我在 Windows
您的脚本丢弃了 run_add
调用的输出。尝试改变这个:
for items in files:
abs_path = script_dir + "\" + items
p4.run_add("-c", changeList, items)
print("Adding file "+ abs_path + " to "+ changeList)
至:
for items in files:
abs_path = script_dir + "\" + items
output = p4.run_add("-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 add
命令的结果。基于 p4 edit
打开文件这一事实,我希望您会发现这样的消息:
C:\Perforce\test>p4 add foo
//stream/main/foo - can't add existing file
p4 add
和 p4 edit
命令不是同义词;一种用于添加新文件,一种用于编辑现有文件。如果您的脚本正在编辑现有文件,它应该调用 run_edit
,而不是 run_add
.
我将我的问题更改为以下并且有效。
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)