pythonperforcep4python

How to check if file is added or in edit mode/checked out?


I'm looking for the commands for these things:

Does file exist in depo? And if so is it checked out?

Is local file added?

Thanks!

(extra info)

I've figured out the commands for add and edit, but I want to check the state first before i run these:

p4.run_add("C:\myfile.txt")
p4.run("edit", "//depot/myfile.txt")

the logic would be:

if file exists in depo and is not checked out:
   check out file
else:
   if file is not added:
      add file

Solution

  • To achieve this you could use fstat.

    Check that file exist:

    fstat_result =p4.run("fstat","//depot/myfile.txt")
    if fstat_result and "otherOpen" not in fstat_result[0]:
        p4.run("edit","//depot/myfile.txt")
    

    Check that local file added:

    fstat_result =p4.run("fstat","C:\myfile.txt")
    if not fstat_result:
        p4.run_add("C:\\myfile.txt")