-
Notifications
You must be signed in to change notification settings - Fork 52
/
CreatePreviewJobFromTasks.py
107 lines (84 loc) · 3.96 KB
/
CreatePreviewJobFromTasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# ---------------------------------------
# Created by Justin Blagden - March 2016
#
# Drop this into your [repo]\custom\scripts\Tasks to install.
# Select one or more tasks to create a preview job out of.
# This will mark the selected tasks as completed on the main job.
# Send all comments, complaints and inqueries to support@thinkboxsoftware.com - be sure to mention Justin in the subject.
# ---------------------------------------
from Deadline.Scripting import *
from Deadline.Jobs import *
from Deadline.Users import *
import os
import socket
def __main__(*args):
selectedTasks = MonitorUtils.GetSelectedTasks()
selectedJobs = MonitorUtils.GetSelectedJobs()
framelist = ""
if len(selectedTasks) > 0 and len(selectedJobs) == 1:
for i, task in enumerate(selectedTasks):
framelist += task.TaskFrameString
if i < len(selectedTasks) - 1:
framelist += ","
# Now set the values we're going to change when we dupe the job files
# Grab our 1 job
selectedJob = selectedJobs[0] # We know we only have one selected job
# We're going to make this *slightly* more important than the original job
highpriority = selectedJob.Priority
# Deadline doesn't allow priorities greater than 100
highpriority += 1
if highpriority > 100:
highpriority = 100
deadlineTemp = ClientUtils.GetDeadlineTempPath()
jobInfoFile = os.path.join(deadlineTemp, "duplicate_job_info.job")
pluginInfoFile = os.path.join(deadlineTemp, "duplicate_plugin_info")
# Create the replacement dictionary
# Defined just like the job or plugin files are
replaceDict = {'Name': 'Preview of %s' % (selectedJob.JobName),
'Frames': framelist,
'Priority': highpriority,
'ChunkSize': 1}
# Create the job and plugin files, replaceing designated key+value pairs
DuplicateJobProperties(selectedJob, jobInfoFile, pluginInfoFile, replaceDict)
# Submit the preview job with our new job files
submissionArray = [jobInfoFile, pluginInfoFile]
auxFiles = selectedJob.JobAuxiliarySubmissionFileNames
submissionArray.extend(auxFiles)
RepositoryUtils.SubmitJob(submissionArray)
# Now we need to make sure that the tasks we've selected are set to
# 'Completed' so we aren't doing work twice
hostname = socket.gethostname()
RepositoryUtils.CompleteTasks(selectedJob, selectedTasks, hostname)
def DuplicateJobProperties(originalJob, jobInfoFile, pluginInfoFile, replaceDict):
# This'll go through the job's properites and copy everything that isn't blank or supposed to be overwritten
# Make the job file
try:
fileHandle = open(jobInfoFile, "w")
# Loop through the JobInfoKeys
for key in originalJob.GetJobInfoKeys():
value = originalJob.GetJobInfoKeyValue(key)
if key in replaceDict:
fileHandle.write("%s=%s\n" % (key, replaceDict[key]))
elif value != "":
fileHandle.write("%s=%s\n" % (key, value))
# Loop through the JobExtraInfoKeys
for key in originalJob.GetJobExtraInfoKeys():
value = originalJob.GetJobExtraInfoKeyValue(key)
if key in replaceDict:
fileHandle.write("%s=%s\n" % (key, replaceDict[key]))
elif value != "":
fileHandle.write("%s=%s\n" % (key, value))
finally:
fileHandle.close()
# Make the plugin file
try:
fileHandle = open(pluginInfoFile, "w")
# Loop through the JobPluginInfo
for key in originalJob.GetJobPluginInfoKeys():
value = originalJob.GetJobPluginInfoKeyValue(key)
if key in replaceDict:
fileHandle.write("%s=%s\n" % (key, replaceDict[key]))
else:
fileHandle.write("%s=%s\n" % (key, value))
finally:
fileHandle.close()