Python 3.7 P4Python不会在Perforce中签出该文件

Python 3.7 P4Python不会在Perforce中签出该文件,python-3.7,perforce,p4python,Python 3.7,Perforce,P4python,我有下面的代码。我正试图从Perforce签出两个文件,并将它们放在变更列表中。但是run\u add不会签出文件。我在Perforce中看到的唯一一件事是一个没有文件的空变更列表 """ Checks out files from workspace using P4""" files = ['analyse-location.cfg', 'CMakeLists.txt'] p4 = P4() # Connect and disconnect if (p4.connected()):

我有下面的代码。我正试图从Perforce签出两个文件,并将它们放在变更列表中。但是
run\u 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\u add
调用的输出。尝试更改此选项:

    for items in files:
        abs_path = script_dir + "\\" + items
        p4.run_add("-c", changeList, items)
        print("Adding file "+ abs_path + " to "+ changeList)
致:

这将显示正在运行的
p4 add
命令的结果。基于
p4 edit
打开文件的事实,我希望您会发现如下消息:

C:\Perforce\test>p4 add foo
//stream/main/foo - can't add existing file

p4 add
p4 edit
命令不是同义词;一个用于添加新文件,一个用于编辑现有文件。如果您的脚本正在编辑现有文件,它应该调用
run\u edit
,而不是
run\u add

您的脚本将丢弃
run\u add
调用的输出。尝试更改此选项:

    for items in files:
        abs_path = script_dir + "\\" + items
        p4.run_add("-c", changeList, items)
        print("Adding file "+ abs_path + " to "+ changeList)
致:

这将显示正在运行的
p4 add
命令的结果。基于
p4 edit
打开文件的事实,我希望您会发现如下消息:

C:\Perforce\test>p4 add foo
//stream/main/foo - can't add existing file

p4 add
p4 edit
命令不是同义词;一个用于添加新文件,一个用于编辑现有文件。如果您的脚本正在编辑现有文件,它应该调用
run\u edit
,而不是
run\u 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\u add(“-c”,changelist,items)
更改为
p4.run\u edit(“-c”,changelist,items)
我将我的问题更改为下面的问题,它成功了

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.运行添加(“-c”,变更列表,项目)
p4.运行编辑(“-c”,变更列表,项目)

我按照您的建议编辑了我的代码。输出错误表示已存在具有该名称的文件,无法添加。文件未签出。一如你所说。我认为run_会将文件添加到CL以进行编辑。我试图实现的是签出一些文件并使它们准备好进行编辑。这就是
p4 edit
命令,正如您已经了解的那样。只要使用正确的命令,它就会工作——有什么问题吗?:)你的意思是“p4.edit”(“c”,changelist,file)。我遇到了一个错误。当我尝试p4.run(“edit”,“changelist,file”)时,我仍然没有在changelist中获取该文件。我将其更改为p4.run\u edit(“-c”,changelist,items),它工作了。是的,它的标志与您最初使用的
run\u add
命令完全相同;只需将
add
(添加文件)更改为
edit
(编辑文件)。我按照您的建议编辑了代码。输出错误表示已存在具有该名称的文件,无法添加。文件未签出。一如你所说。我认为run_会将文件添加到CL以进行编辑。我试图实现的是签出一些文件并使它们准备好进行编辑。这就是
p4 edit
命令,正如您已经了解的那样。只要使用正确的命令,它就会工作——有什么问题吗?:)你的意思是“p4.edit”(“c”,changelist,file)。我遇到了一个错误。当我尝试p4.run(“edit”,“changelist,file”)时,我仍然没有在changelist中获取该文件。我将其更改为p4.run\u edit(“-c”,changelist,items),它工作了。是的,它的标志与您最初使用的
run\u add
命令完全相同;只需将
add
(添加文件)更改为
edit
(编辑文件)。