【问题标题】:P4Python does not check out the file in PerforceP4Python 不会在 Perforce 中签出文件
【发布时间】:2020-02-18 16:28:27
【问题描述】:

我有以下代码。我正在尝试从 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 位

【问题讨论】:

    标签: python-3.7 perforce p4python


    【解决方案1】:

    您的脚本丢弃了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 addp4 edit 命令不是同义词;一种用于添加新文件,一种用于编辑现有文件。如果您的脚本正在编辑现有文件,它应该调用run_edit,而不是run_add

    【讨论】:

    • 我按照您的建议编辑了我的代码。输出错误表示已经有一个具有该名称的文件并且无法添加。该文件未检出。正如你所说。我认为 run_adds 将文件添加到 CL 以进行编辑。我想要实现的是检查一些文件并准备好进行编辑。
    • 这就是p4 edit 命令,正如您已经知道的那样。只需使用正确的命令,它就会起作用——有什么问题? :)
    • 你的意思是“ p4.edit("c", changelist, file) 。我得到一个错误。当我尝试 p4.run("edit","changelist, file) 我仍然没有获取更改列表中的文件
    • 我将其更改为 p4.run_edit("-c", changelist, items) 并且它起作用了。
    • 是的,它与您最初使用的run_add 命令完全相同;只需将add(添加文件)更改为edit(编辑文件)。
    【解决方案2】:

    我将我的问题改为关注,它奏效了。

    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)

    【讨论】:

      猜你喜欢
      • 2010-09-16
      • 1970-01-01
      • 2012-03-05
      • 1970-01-01
      • 2010-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多