Here is what I implemented to check if a tool is up to date (according to Perforce).
I end up using the P4Python library. It was easy to connect with P4, set the client (workspace) and user then query a file path to see if A) it’s in the workspace, and B) is up to date.
## Query P4 whether a script is up to date.
def check_version(supplied_path = None):
stack = inspect.stack()
if supplied_path == None:
script_path = inspect.getfile(stack[1][0])
else:
script_path = supplied_path
from P4 import P4, P4Exception
p4 = P4()
with p4.connect():
print 'Connected with P4'
user_name = get_perforce_user()
client_name = get_perforce_client()
print 'P4 username : ' + user_name
print 'P4 workspace : ' + client_name
if client_name is not None and user_name is not None:
p4.user = user_name
p4.client = client_name
try:
localRev = p4.run_have(script_path)[0]['haveRev']
headRev = p4.run_files(script_path)[0]['rev']
if localRev < headRev:
cmds.warning(script_path + ' is out of date.')
return False
elif localRev == headRev:
print script_path + ' is up to date.'
return True
except P4Exception:
for e in p4.errors:
cmds.warning(e)
return False
The section that has worked so far, but I’m not super confident about is this line:
script_path = inspect.getfile(stack[1][0])
Since I have multiple classes calling this function, I wanted to keep that call as simple as possible. So I looked for a way for that function to get the class that called it, and use that information to derive the script path.
So from there, I edited my tools to call check_version(), and the window’s version label is displayed in red if function returns False.
I am, however, still exploring better options discussed in this thread. Having read through the links Theodox posted, I now have a better understanding of preferred practices, such as using a single ‘launcher’ application for the artists to boot up which houses the utility tools.