Reputation: 13
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
Upvotes: -1
Views: 49
Reputation: 510
result = p4.run_fstat("//depot/myfile.txt")
if result:
# File exists in depot
if 'action' in result[0] and result[0]['action'] == 'edit':
print("File is already checked out.")
else:
# File exists but is not checked out
print("Checking out file...")
p4.run("edit", "//depot/myfile.txt")
else:
# File does not exist or is not added locally
print("Adding file to the depot...")
p4.run_add("C:/myfile.txt")
Upvotes: 1
Reputation: 1279
To achieve this you could use fstat
.
fstat_result =p4.run("fstat","//depot/myfile.txt")
if fstat_result and "otherOpen" not in fstat_result[0]:
p4.run("edit","//depot/myfile.txt")
fstat_result =p4.run("fstat","C:\myfile.txt")
if not fstat_result:
p4.run_add("C:\\myfile.txt")
Upvotes: 1