-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubmitterMain.py
214 lines (175 loc) · 7.8 KB
/
SubmitterMain.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import sys
import traceback
import math
import os
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from Ui_submitter import Ui_MainWindow
from LoggingSetup import logger
import JobTicket
from MySQLSetup import transaction, Hydra_rendernode
import Utils
from MessageBoxes import aboutBox, yesNoBox
class SubmitterWindow( QMainWindow, Ui_MainWindow ):
def __init__( self ):
"""Initializes the Maya render job submission window."""
QMainWindow.__init__( self )
self.setupUi( self ) #self, self
QObject.connect(self.submitButton, SIGNAL("clicked()"),
self.doSubmit)
QObject.connect(self.browseButton, SIGNAL("clicked()"),
self.setMayaProjectPath)
self.requirementsListWidget.setSelectionMode (QAbstractItemView.MultiSelection)
if len (sys.argv) < 2:
sys.argv.append ('???')
sys.argv.extend (['1', '1', '1'])
scene, start, end, by = sys.argv[1:5] # _TODO: proper command line args
scene = scene.replace ('\\', '/')
self.sceneText.setText(scene)
self.startSpinBox.setValue( eval (start ) )
self.endSpinBox.setValue( eval( end ) )
self.populateProjectComboBox()
self.populateExecutableComboBox()
self.populateRequirementsListWidget()
def populateProjectComboBox(self):
"""Populates the projects dropdown box."""
# get current list of projects from the database
tuples = None
with transaction() as t:
t.cur.execute("select * from Hydra_projects")
tuples = t.cur.fetchall()
# flatten list of tuples fetched from the database
projectsList = [t for (t,) in tuples]
# populate the dropdown
for project in projectsList:
self.projectComboBox.addItem(project)
# show default project selection
[thisNode] = Hydra_rendernode.fetch(
"where host = '%s'" % Utils.myHostName())
idx = self.projectComboBox.findText(
thisNode.project,
flags=Qt.MatchExactly|Qt.MatchCaseSensitive)
self.projectComboBox.setCurrentIndex(idx)
def populateExecutableComboBox(self):
"""Populates the executables dropdown box."""
# get current list of executables from the database
tuples = None
with transaction() as t:
t.cur.execute("select * from Hydra_executable")
tuples = t.cur.fetchall()
# flatten list of tuples fetched from the database
executables = [t for (t,) in tuples]
# populate the dropdown
for program in executables:
self.executableComboBox.addItem(program)
def populateRequirementsListWidget(self):
"""Populates the requirements list widget."""
# get current list of capabilities from the database
tuples = None
with transaction() as t:
t.cur.execute("select * from Hydra_capabilities order by name")
tuples = t.cur.fetchall()
# flatten list of tuples fetched from the database
capabilities = [t for (t,) in tuples]
# populate the dropdown
for item in capabilities:
self.requirementsListWidget.addItem(item)
## # show default project selection
## [thisNode] = Hydra_rendernode.fetch(
## "where host = '%s'" % Utils.myHostName())
## idx = self.projectComboBox.findText(
## thisNode.project,
## flags=Qt.MatchExactly|Qt.MatchCaseSensitive)
## self.projectComboBox.setCurrentIndex(idx)
# called by pressing the "submit" button in the Qt main window
def doSubmit( self ):
"""Submits a job ticket for this scene to be split into
tasks and processed."""
logger.debug ('doSubmit')
reqs = sorted ([str (req.text ())
for req in self.requirementsListWidget.selectedItems ()])
reqs_pattern = '%' + '%'.join (reqs) + '%' if reqs else '%'
print reqs_pattern
sceneFile = str( self.sceneText.text() ).replace ('\\', '/')
startFrame = self.startSpinBox.value( )
endFrame = self.endSpinBox.value( )
numJobs = self.numJobsSpinBox.value( )
batchSize = int(math.ceil((endFrame - startFrame + 1.0) / numJobs))
logger.debug ("numJobs %s batchSize %s", numJobs, batchSize)
priority = self.prioritySpinBox.value( )
project = str(self.projectComboBox.currentText())
executable = str(self.executableComboBox.currentText())
mayaProjectPath = str(self.projectDirLineEdit.text())
if not os.path.exists(os.path.join (mayaProjectPath, "workspace.mel")):
# try to find workspace.mel
mayaProjectPath = self.getMayaProjectPath(sceneFile)
if not mayaProjectPath:
logger.debug("workspace.mel not found")
aboutBox(self, "Error", """
The project path cannot be set because workspace.mel could not
be located. Please set the project path manually.""")
return
if yesNoBox(self, "Confirm",
"Maya project path set to:<br>" +
mayaProjectPath +
"<br> Is this correct?") == QMessageBox.No:
aboutBox(self, "Abort",
"Submission aborted. Please set the Maya project path manually.")
return
self.projectDirLineEdit.setText(mayaProjectPath)
# executable names a class in the JobTicket module
ticketClass = getattr (JobTicket, executable)
ticketClass(sceneFile, mayaProjectPath, startFrame, endFrame, batchSize,
priority, project, reqs_pattern).submit()
aboutBox(self, "Success",
"Job submitted. Please close the submitter window.")
def getMayaProjectPath(self, scenePath):
"""
Walks up the file tree looking for workspace.mel,
returns the path if found"""
# remove Maya scene file name from the end of the path
mayaProjectPath = os.path.dirname (scenePath)
lastPath = None
wrkspc = "workspace.mel"
while not os.path.exists(os.path.join(mayaProjectPath, wrkspc)):
logger.debug ("%s not in %s", wrkspc, mayaProjectPath)
lastPath = mayaProjectPath
mayaProjectPath = os.path.dirname (mayaProjectPath)
if lastPath == mayaProjectPath:
return ""
return mayaProjectPath
def setMayaProjectPath(self):
"""
Opens a file browser dialog for finding workspace.mel,
tries to start the user somewhere sensible"""
currentDir = str( self.projectDirLineEdit.text() )
startDir = None
if len(currentDir) == 0:
sceneFile = str( self.sceneText.text() )
startDir = self.getMayaProjectPath(sceneFile)
if not startDir:
startDir = os.getcwd()
else:
startDir = currentDir
mayaProjectPath = QFileDialog.getOpenFileName(
parent=self,
caption="Find workspace.mel",
directory=startDir,
filter="workspace.mel")
if mayaProjectPath:
# remove "workspace.mel" from the end of the path
mayaProjectPath = str(mayaProjectPath).split('/')
mayaProjectPath.pop()
mayaProjectPath = '/'.join(mayaProjectPath) + '/'
self.projectDirLineEdit.setText(mayaProjectPath)
if __name__ == '__main__':
try:
logger.debug(sys.argv) # prints out argv
app = QApplication( sys.argv )
window = SubmitterWindow( )
window.show( )
retcode = app.exec_( )
sys.exit( retcode )
except Exception, e:
logger.error( traceback.format_exc( e ) )
raise