DavidJ Posted September 21, 2017 Report Share Posted September 21, 2017 We have a Unity scene file that we don't want artists to check in but which Unity keeps marking as dirty and checking out from Plastic. I've written a before-clientcheckin trigger in Python that is designed to give the user the option to undo changes to the file. here's the Python script: #! /usr/bin/python import sys import os from subprocess import Popen, PIPE from threading import Thread import ctypes def cmdline(command): process = Popen( args=command, stdout=PIPE, shell=True ) return process.communicate()[0] filePath = "..\\..\\Assets\\Scenes\\DialogTree_01.unity" checkedOut = "CO "+filePath; undoCommand = "cm unco "+filePath+" --all"; statusOutput = cmdline("cm status") foundTOY = statusOutput.find(checkedOut) if foundTOY > 0: choice = ctypes.windll.user32.MessageBoxW(0, u'You are checking in DialogTree_01.unity which you should only do if a new sector has been added. Would you like to revert it?', u'Warning', 4) if choice == 6: #! yes os.system(undoCommand) If I run this script from the command line then it works as expected with the command 'cm status' always returns a valid string containing the checked out files and undo-ing the checkout if requested. But if I set it as a trigger with the following command cm mktrigger before-clientcheckin "check for TheOtherYou.unity" "python @WKSPACE_PATH/Tools/Python/PlasticCheckinTrigger.py" then the script executes but the command 'cm status' always returns a null string so the message box never comes up. Is it valid to execute the 'cm xxx' commands in a trigger and if so what am I doing wrong? Link to comment Share on other sites More sharing options...
manu Posted September 22, 2017 Report Share Posted September 22, 2017 Hi @DavidJ, I have just tested an small trigger, similar to yours and it works for me: I can execute "cm" commands, you can see the "status" output inside the warning popup dialog. I created the trigger like this: cm maketrigger before-checkin "pyton_trigger" "c:\Python27\python.exe c:\Users\manu\Desktop\trigger.py" And this is the code: #! /usr/bin/python import sys import os from subprocess import Popen, PIPE from threading import Thread import ctypes def cmdline(command): process = Popen( args=command, stdout=PIPE, shell=True ) return process.communicate()[0] filePath = "girl.txt" checkedOut = " CO " + str(filePath) undoCommand = "cm unco "+ filePath +" --all"; sys.stdout.write("Running status command...") statusOutput = cmdline("cm status c:\Users\manu\wkspaces\default_22") choice = ctypes.windll.user32.MessageBoxW(0, u'Out: ' + statusOutput, u'Warning', 4) if checkedOut not in statusOutput: sys.stdout.write("File NOT found in status"+ '\r\n') exit() sys.stdout.write("File found in status"+ '\r\n') choice = ctypes.windll.user32.MessageBoxW(0, u'You are checking in DialogTree_01.unity which you should only do if a new sector has been added. Would you like to revert it?', u'Warning', 4) if choice == 6: #! yes sys.stdout.write("Okay... Undoing") os.system(undoCommand) exit() sys.stdout.write("File not undone") Hope it helps! Link to comment Share on other sites More sharing options...
DavidJ Posted September 22, 2017 Author Report Share Posted September 22, 2017 thanks for your reply, it helped me identify that the problem with my code is that when the script is executed by Plastic the current working directory is the Plastic install directory rather than the workspace and so the 'cm xxx' functions return nothing because they're using relative paths. In case anyone is interested I've rewritten the script so that it doesn't need to know where the workspace is on disc, instead it scans the stdin for the absolute path of the files that are being checked in. #! /usr/bin/python import sys import os from subprocess import Popen, PIPE from threading import Thread import ctypes def cmdline(command): process = Popen( args=command, stdout=PIPE, shell=True ) return process.communicate()[0] def find_1st(string, substring): return string.find(substring) def find_2nd(string, substring): return string.find(substring, string.find(substring) + 1) filePath = "DialogTree_01.unity" for line in sys.stdin: if filePath in line: fp = line[find_1st(line,'"')+1:find_2nd(line,'"')] choice = ctypes.windll.user32.MessageBoxW(0, u'You are checking in '+fp+' which you should only do if a new sector has been added. Would you like to revert it?', u'Warning', 4) if choice == 6: #! yes undoCommand = "cm unco "+ fp +" --all"; os.system(undoCommand) exit() Link to comment Share on other sites More sharing options...
manu Posted September 25, 2017 Report Share Posted September 25, 2017 Nice!! Thanks for sharing it! Link to comment Share on other sites More sharing options...
DavidJ Posted September 27, 2017 Author Report Share Posted September 27, 2017 It seems I spoke a bit to soon @manu The script executes OK but the file that is meant to be unchecked out still gets checked in. Is it valid to execute an uncheckout command during a pre commit trigger? Link to comment Share on other sites More sharing options...
manu Posted September 27, 2017 Report Share Posted September 27, 2017 Hello @DavidJ, I'm sorry I took for granted you will undo the file and cancel the checkin... I didn't read the trigger body properly either. It's not possible to undo an continue with the rest, you'll need to undo, cancel the checkin and let the user checkin again. Link to comment Share on other sites More sharing options...
DavidJ Posted September 27, 2017 Author Report Share Posted September 27, 2017 thanks for the reply @manu - what's the best way of cancelling the checkin from Python script? Link to comment Share on other sites More sharing options...
manu Posted September 27, 2017 Report Share Posted September 27, 2017 Just return an error code from the trigger with an informative message. Link to comment Share on other sites More sharing options...
DavidJ Posted September 27, 2017 Author Report Share Posted September 27, 2017 I can't get it to undo the checkout. If I execute the 'cm unco' command and then exit from the trigger with an error code then the file remains checked out Link to comment Share on other sites More sharing options...
manu Posted September 27, 2017 Report Share Posted September 27, 2017 It turns out the workspace is locked so you can't undo a file during the checkin operation. I'll try to find a solution without requiring a dirty hack (removing the lock file manually -> wkpah/.plastic/plastic.lck) Link to comment Share on other sites More sharing options...
DavidJ Posted October 5, 2017 Author Report Share Posted October 5, 2017 hi, did you manage to find another solution? If we manually removed the lock file would that be dangerous - i.e could we get corrupt files or a corrupt db - or do you think it's safe? Link to comment Share on other sites More sharing options...
manu Posted October 5, 2017 Report Share Posted October 5, 2017 Hi @DavidJ, I'm afraid I can't find any other way to do it. Removing the lock is safe, I don't like it, it's ugly, but I can't find another way Link to comment Share on other sites More sharing options...
DavidJ Posted October 17, 2017 Author Report Share Posted October 17, 2017 I've tried removing the lock but I can't because during the pre checkin stage Plastic has the file open. Is there a way of doing it? Link to comment Share on other sites More sharing options...
DavidJ Posted October 26, 2017 Author Report Share Posted October 26, 2017 bump Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.