Jump to content

Before-Client Checkin Trigger


DavidJ

Recommended Posts

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

Hi @DavidJ,

I have just tested an small trigger, similar to yours and it works for me:

tri.png

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

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

  • 2 weeks later...
  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...