python-3.7 - P4Python 不会在 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)
将文件放在默认更改列表中时。它真的让我很紧张。我不知道我这样做是错误的。还创建了更改列表。我在 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
正在运行的命令的结果。基于 ap4 edit
打开文件的事实,我希望您会找到这样的消息:
C:\Perforce\test>p4 add foo
//stream/main/foo - can't add existing file
和命令不是同义词p4 add
;p4 edit
一种用于添加新文件,一种用于编辑现有文件。如果您的脚本正在编辑现有文件,它应该调用run_edit
,而不是run_add
.
推荐阅读
- objective-c - NSOutlineView 拖放(在项目旁边)不适用于复杂项目
- python - 如何使用 OpenCV 中的 Tkinter 显示图像
- laravel - Laravel 5.6 - 404 虽然定义了路由
- c - 将数字分配给C中的char变量?
- javascript - Javascript/Angular Basics - 从范围中读取一个简单的值
- javascript - 使用 jQuery 的类和值不为空的所有选择列表选项
- swift - 如何子类化 AVCaptureInput 和 AVCaptureInput.Port?
- java - Ant 没有使用我的 JAVA_HOME 来查找 tools.jar
- java - Java - 如何在 if 语句中添加 rgb 值?
- c# - 是否有 api 接口可以与 Unreal 进行材质交换?