Event Scripting Help

I have written a event script that takes certain deadline jobs outputs and turns them into quicktimes. The only trouble is that if for some reason the qt render fails the file is incomplete and is left in a state that it can’t be over-written the next time the job tries to create the quicktime.

I would like to somehow make the script change the render output to a temp folder and once finished copy it to it’s original destination. I’m fairly sure this is possible but I’m looking for any advice on how I might go about it and what commands might be useful or if anyone has an example where this has been done before.

Thanks in advance,

Can you post your current event plugin? We can look at that and offer suggestions on how to do this.

Thanks!

  • Ryan

Thanks russell! here it is, There is still a lot of read-out code in there and just so you know i’m in the “figure it out as I go” coding level so I am sure there are some noob mistakes in there.

[code]from System.IO import *
from System.Text import *

from Deadline.Events import *
from Deadline.Scripting import *

def GetDeadlineEventListener():
return MyEvent()

class MyEvent (DeadlineEventListener):

def OnJobStarted( self, job ):
	# Get the location of the output files	
	outputDirectories = job.JobOutputDirectories[0]
	outputFilenames = job.JobOutputFileNames[0]
	frames = job.JobFrames
	jobPlug = job.JobPlugin
	templatePath = "V:\\TestAscii.comp"
	#pre-defined area
	if outputDirectories == "" or job.JobComment == "Auto-submitted Fusion File" : return 

	print outputDirectories
	print outputFilenames
	print frames
	print FrameUtils.Parse(frames)
	def quoteWrap(n):
		result = "\"" + n + "\""
		return result
	shortDirPath = ""

	extentionTypes = ["tga","iff","tif","png","exr","rla","hdr","mov"]
	fusionExt = ["TargaFormat","MayaIFFFormat","TiffFormat","PNGFormat"
				,"OpenEXRFormat","rlaFormat","HDRFormat","Quicktime"]
	swapChar = ["#","?","?","?","?"]
	#get the filename with no extention
	fileNameSplit = outputFilenames.split(".")
	
	#get extention and figure out which file format it is
	inputExtentionType = fileNameSplit[len(fileNameSplit) -1]
	
	cnt = 0
	while inputExtentionType != extentionTypes[cnt] :
		cnt=cnt +1
		if cnt > len(extentionTypes) :
			break
	newExt =  quoteWrap(fusionExt[cnt])
	print cnt
	if cnt == 7 or fusionExt[cnt] == "\"Quicktime\"" :
		print "Quicktime detected Exiting"
		return

	print jobPlug
	inPlug = ["AfterEffects","Fusion","FusionCmd","MayaBatch","MayaCmd"]
	plugCnt =0
	while jobPlug != inPlug[plugCnt] :
		plugCnt=plugCnt + 1
		if plugCnt > len(inPlug) :
			print "render Plug not defined"
			return
	newExt =  quoteWrap(fusionExt[cnt])
	
	if plugCnt == 3 or plugCnt == 4:
		print "Maya Job Detected - exiting"
		return
	print inPlug[plugCnt]
	print swapChar[plugCnt]
	print extentionTypes[cnt]
	print fusionExt[cnt]
	print newExt
	
	#get the first and end frames
	frameList = FrameUtils.Parse(frames)
	firstFrame = frameList[0]
	lastFrame = frameList[len(frameList)-1]
	frameLength = len(frameList)
	fristFrameString = str(firstFrame)
	print firstFrame
	print lastFrame
	print frameLength
	frame = frames.split("-")
	newFrameRange = "0-" + str(frameLength-1)
	print newFrameRange
	#get the path and filename of input file clean and ready for fusion
	
	filePathF = outputDirectories + "\\" +  outputFilenames
	print filePathF
	filePathF = filePathF.replace(swapChar[plugCnt], fristFrameString)
	filePathF = quoteWrap(filePathF)
	filePathF = filePathF.replace("\\", "\\\\")
	
	#create new outputPath for resulting quicktime
	fileNameSplit = fileNameSplit[0].split(swapChar[plugCnt])
	QTname = fileNameSplit[0] + ".mov"
	splitDir = outputDirectories.split("\\")
	shortDir = splitDir[0:(len(splitDir)-1)]
	for x in shortDir:
		shortDirPath = shortDirPath + x + "\\"

	qtOutputPath = shortDirPath + QTname
	if FileExists(qtOutputPath) :
		print "Deleting Existing QT File"
		File.Delete(qtOutputPath)
		
	qtOutputPath = qtOutputPath.replace("\\","\\\\")

	print shortDirPath
	print qtOutputPath
	if not Directory.Exists(shortDirPath):
		Directory.CreateDirectory(shortDirPath)
		print ("created output directory" + shortDirPath)
	
	qtOutputPath = quoteWrap(qtOutputPath)
	#get the template file
	templateLoc = templatePath
	#open the "template file"
	templateFile = open(templateLoc,"r")
	#replace comp globals with frame range
	fileText = templateFile.read()
	fileText = fileText.replace("clipStart",frame[0])
	fileText = fileText.replace("clipEnd",str(frameLength))
	fileText = fileText.replace("globalStart","0")
	fileText = fileText.replace("globalEnd",str((frameLength+5)))
	fileText = fileText.replace("renderStart","0")
	fileText = fileText.replace("renderEnd",str(frameLength-1))
	fileText = fileText.replace("frameLen", str(frameLength))
	fileText = fileText.replace("inputFileFormat", newExt)
	#replace comp loader and file name
	fileText = fileText.replace("fileNameInput", filePathF)
	fileText = fileText.replace("qtOutputPath", qtOutputPath)
	#write to new file in directory
	newFileName = shortDirPath+fileNameSplit[0]+"_render.comp"
	newFile = open(newFileName, "w")
	newFile.writelines(fileText)
	#close file
	newFile.close
	templateFile.close
	
	#submit file to deadline fusion encode
	print QTname
	print job.JobId
	# Create job info file.
	jobInfoFilename = Path.Combine( ClientUtils.GetDeadlineTempPath(), "fusion_job_info.job" )
	writer = StreamWriter( jobInfoFilename, False, Encoding.Unicode )
	writer.WriteLine( "Plugin=FusionEncoder" )
	writer.WriteLine( "Name=%s" % QTname )
	writer.WriteLine( "Comment=Auto-submitted Fusion File" )
	writer.WriteLine( "Department=%s" % job.JobDepartment )
	writer.WriteLine( "Pool=fusionencode" )
	writer.WriteLine( "Group=%s" % job.JobGroup )
	writer.WriteLine( "Priority=%s" % job.JobPriority )
	writer.WriteLine( "MachineLimit=1" )
	writer.WriteLine( "Frames=%s" % newFrameRange )
	writer.WriteLine( "ChunkSize=100000" )
	writer.WriteLine( "OutputFilename0=%s" % shortDirPath )
	writer.WriteLine( "OutputFile0=%s" % QTname )
	writer.WriteLine( "JobDependencies=%s" % job.JobId )
	writer.WriteLine( "JobDependencyPercentage=90" )
	writer.Close()
	
	# Create plugin info file.
	pluginInfoFilename = Path.Combine( ClientUtils.GetDeadlineTempPath(), "fusion_plugin_info.job" )
	writer = StreamWriter( pluginInfoFilename, False, Encoding.Unicode )
	writer.WriteLine( "Version=6.31" )
	writer.WriteLine( "Build=64bit" )
	writer.WriteLine( "FlowFile=%s" % newFileName )
	writer.Close()
	print jobInfoFilename
	print pluginInfoFilename
	# Now submit the job.
	ClientUtils.ExecuteCommand( (jobInfoFilename,pluginInfoFilename) )
def OnJobFailed(self, job):
	print "I failed to render this job that I don't know the name of"
def OnJobFinished(self, job):
	if job.JobComment != "Auto-submitted Fusion File" : return 
	print "I know I finished a Fusion Auto Job, I want to delete a folder now"
	print "this folder %s" % job.JobOutputDirectories[0]
	filesInD = Directory.GetFiles(job.JobOutputDirectories[0])
	print filesInD

[/code]

Thanks! I can see that you’re submitting a new job to your FusionEncoder plugin, so that means you’ll have to handle writing to a temp file and copying to the final location in your FusionEncoder plugin. Perhaps it could replace the qtOutputPath with a local temp path, and then when the render is finished, copy it to the original path. It would probably be best to try and do this all within the FusionEncoder plugin so that it’s all in one place.