def publish(self, settings, item): """ Executes the publish logic for the given item and settings. :param settings: Dictionary of Settings. The keys are strings, matching the keys returned in the settings property. The values are `Setting` instances. :param item: Item to process """ publisher = self.parent # get the path to create and publish publish_path = item.properties["path"] # ensure the publish folder exists: publish_folder = os.path.dirname(publish_path) self.parent.ensure_folder_exists(publish_folder) # set the alembic args that make the most sense when working with Mari. # These flags will ensure the export of an USD file that contains # all visible geometry from the current scene together with UV's and # face sets for use in Mari. usd_args = [ '-shd "none"', '-dms "none"', '-uvs 1', '-cls 0', '-vis 1', '-mt 0', '-sl', '-sn 1', '-fs %f' % item.properties['sub_frame'], '-ft %f' % item.properties['sub_frame'] ] # find the animated frame range to use: start_frame, end_frame = _find_scene_animation_range() if start_frame and end_frame: usd_args.append("-fr %d %d" % (start_frame, end_frame)) # Set the output path: # Note: The AbcExport command expects forward slashes! sub_components = [ x for x in cmds.ls(allPaths=1, ca=0, transforms=1, l=1) if cmds.listRelatives(x, p=1) and cmds.attributeQuery("Meshtype", node=x, exists=1) and cmds.getAttr(x + ".Meshtype", asString=True) == "component" ] if not sub_components: usd_args.append('-f "%s"' % publish_path.replace("\\", "/")) usd_export_cmd = ("usdExport %s" % " ".join(usd_args)) else: asset_usd_path = self._get_sub_component_path( item.properties['name'], item) usd_args.append('-f "%s"' % asset_usd_path.replace("\\", "/")) usd_export_cmd = ("usdExport %s" % " ".join(usd_args)) script = '' script += 'import maya.standalone\n' script += 'maya.standalone.initialize()\n' script += 'import maya.cmds as cmds\n' script += 'import maya.mel as mel\n' script += '\n' script += '\n' script += 'cmds.file("{}",open=1,force=1,iv=1)\n'.format( cmds.file(query=True, sn=True)) script += 'cmds.select("{}")\n'.format(item.properties['name']) script += 'cmds.loadPlugin("pxrUsd.so")\n' script += 'mel.eval(\'{}\')\n'.format(usd_export_cmd) tmp_path = os.path.splitext(item.properties["path"])[0] + ".py" with open(tmp_path, 'w') as f: f.write(script) import sys sys.path.append( "/westworld/inhouse/tool/rez-packages/tractor/2.2.0/platform-linux/arch-x86_64/lib/python2.7/site-packages" ) import tractor.api.author as author job = author.Job() job.service = "convert" job.priority = 50 file_title = cmds.file(query=True, sn=True).split(".")[0].split("/")[-1] project_name = item.context.project['name'] user_name = item.context.user['name'] user_id = os.environ['USER'] temp = "] [" title = [] title.append(user_name) title.append(project_name) title.append(file_title) title.append(item.properties['name']) title.append("%d - %d" % (start_frame, end_frame)) title = temp.join(title) title = "[" + title + "]" job.title = str(title) command = ['rez-env', 'maya-2019vfarm', 'usd-19.03', '--', 'mayapy'] command.append(tmp_path) command = author.Command(argv=command) task = author.Task(title=str(item.properties['name'])) task.addCommand(command) rm_command = ['/bin/rm', '-f'] rm_command.append(tmp_path) rm_command = author.Command(argv=rm_command) rm_task = author.Task(title="rm tmp") rm_task.addCommand(rm_command) rm_task.addChild(task) job.addChild(rm_task) job.spool(hostname="10.0.20.82", owner=user_id) return
def __acquireTask(self, batch, dispatchData): # If we've already created a task for this batch, then # just return it. The Tractor API will take care of turning # it into an Instance if we add it as a subtask of more than # one parent. task = dispatchData["batchesToTasks"].get(batch) if task is not None: return task # Make a task. nodeName = batch.node().relativeName(dispatchData["scriptNode"]) task = author.Task(title=nodeName) if batch.frames(): # Generate a `gaffer execute` command line suitable for # executing all the frames in the batch. frames = str( IECore.frameListFromList([int(x) for x in batch.frames()])) task.title += " " + frames args = [ "gaffer", "execute", "-script", dispatchData["scriptFile"], "-nodes", nodeName, "-frames", frames, ] scriptContext = dispatchData["scriptNode"].context() contextArgs = [] for entry in [ k for k in batch.context().keys() if k != "frame" and not k.startswith("ui:") ]: if entry not in scriptContext.keys( ) or batch.context()[entry] != scriptContext[entry]: contextArgs.extend( ["-" + entry, IECore.repr(batch.context()[entry])]) if contextArgs: args.extend(["-context"] + contextArgs) # Create a Tractor command to execute that command line, and add # it to the task. command = author.Command(argv=args) task.addCommand(command) # Apply any custom dispatch settings to the command. tractorPlug = batch.node()["dispatcher"].getChild("tractor") if tractorPlug is not None: ## \todo Remove these manual substitutions once #887 is resolved. # Note though that we will need to use `with batch.context()` to # ensure the substitutions occur in the right context. command.service = batch.context().substitute( tractorPlug["service"].getValue()) command.tags = batch.context().substitute( tractorPlug["tags"].getValue()).split() # Remember the task for next time, and return it. dispatchData["batchesToTasks"][batch] = task return task
def test_all(): """This test covers setting all possible attributes of the Job, Task, Command, and Iterate objects. """ job = author.Job() job.title = "all attributes job" job.after = datetime.datetime(2012, 12, 14, 16, 24, 5) job.afterjids = [1234, 5678] job.paused = True job.tier = "express" job.projects = ["animation"] job.atleast = 2 job.atmost = 4 job.newAssignment("tempdir", "/tmp") job.newDirMap(src="X:/", dst="//fileserver/projects", zone="UNC") job.newDirMap(src="X:/", dst="/fileserver/projects", zone="NFS") job.etalevel = 5 job.tags = ["tag1", "tag2", "tag3"] job.priority = 10 job.service = "linux||mac" job.envkey = ["ej1", "ej2"] job.comment = "this is a great job" job.metadata = "show=rat shot=food" job.editpolicy = "canadians" job.addCleanup(author.Command(argv="/utils/cleanup this")) job.newCleanup(argv=["/utils/cleanup", "that"]) job.addPostscript(author.Command(argv=["/utils/post", "this"])) job.newPostscript(argv="/utils/post that") compTask = author.Task() compTask.title = "render comp" compTask.resumeblock = True compCommand = author.Command() compCommand.argv = "comp /tmp/*" compTask.addCommand(compCommand) job.addChild(compTask) for i in range(2): task = author.Task() task.title = "render layer %d" % i task.id = "id%d" % i task.chaser = "chase file%i" % i task.preview = "preview file%i" % i task.service = "services&&more" task.atleast = 7 task.atmost = 8 task.serialsubtasks = 0 task.addCleanup(author.Command(argv="/utils/cleanup file%i" % i)) command = author.Command() command.argv = "prman layer%d.rib" % i command.msg = "command message" command.service = "cmdservice&&more" command.tags = ["tagA", "tagB"] command.metrics = "metrics string" command.id = "cmdid%i" % i command.refersto = "refersto%i" % i command.expand = 0 command.atleast = 1 command.atmost = 5 command.samehost = 1 command.envkey = ["e1", "e2"] command.retryrc = [1, 3, 5, 7, 9] command.resumewhile = [ "/usr/utils/grep", "-q", "Checkpoint", "file.%d.exr" % i ] command.resumepin = bool(i) task.addCommand(command) compTask.addChild(task) iterate = author.Iterate() iterate.varname = "i" iterate.frm = 1 iterate.to = 10 iterate.addToTemplate( author.Task(title="process task", argv="process command")) iterate.addChild(author.Task(title="process task", argv="ls -l")) job.addChild(iterate) instance = author.Instance(title="id1") job.addChild(instance) print job.asTcl()
def batch_render(self): scene = self.bl_scene rm = scene.renderman frame_begin = self.bl_scene.frame_start frame_end = self.bl_scene.frame_end by = self.bl_scene.frame_step if not rm.external_animation: frame_begin = self.bl_scene.frame_current frame_end = frame_begin job = author.Job() scene_name = self.bl_scene.name bl_view_layer = self.depsgraph.view_layer.name job_title = 'untitled' if not bpy.data.filepath else \ os.path.splitext(os.path.split(bpy.data.filepath)[1])[0] job_title += ' %s ' % bl_view_layer job_title += " frames %d-%d" % (frame_begin, frame_end) if frame_end \ else " frame %d" % frame_begin job.title = str(job_title) job.serialsubtasks = True job.service = 'PixarRender' self.add_job_level_attrs(job) threads = self.bl_scene.renderman.batch_threads anim = (frame_begin != frame_end) tasktitle = "Render %s" % (str(scene_name)) parent_task = author.Task() parent_task.title = tasktitle self.generate_rib_render_tasks(anim, parent_task, tasktitle, frame_begin, frame_end, by, threads) job.addChild(parent_task) # Don't denoise if we're baking if rm.hider_type == 'RAYTRACE': parent_task = self.generate_denoise_tasks(frame_begin, frame_end, by) job.addChild(parent_task) bl_filename = bpy.data.filepath if bl_filename == '': jobfile = string_utils.expand_string('<OUT>/<scene>.<layer>.alf', asFilePath=True) else: jobfile = os.path.splitext( bl_filename)[0] + '.%s.alf' % bl_view_layer.replace(' ', '_') jobFileCleanup = author.Command(local=False) jobFileCleanup.argv = [ "TractorBuiltIn", "File", "delete", "%%D(%s)" % jobfile ] job.addCleanup(jobFileCleanup) try: f = open(jobfile, 'w') as_tcl = job.asTcl() f.write(as_tcl) f.close() except IOError as ioe: rfb_log().error('IO Exception when writing job file %s: %s' % (jobfile, str(ioe))) return except Exception as e: rfb_log().error('Could not write job file %s: %s' % (jobfile, str(e))) return self.spool(job, jobfile)
def build(self): self.__mayascenefullpath = "%s/%s" % (self.mayaprojectpath, self.mayascene) self.__mayascenebase = os.path.splitext(self.mayascene)[0] self.job = author.Job(title="MayaBatch Render Job", priority=100, envkey=["maya%s" % self.mayaversion], service="PixarRender") ############### task 1 ############## task = author.Task(title="Make output directory", service="PixarRender") makediectory = author.Command( argv=["mkdir", os.path.join(self.mayaprojectpath, "images")]) task.addCommand(makediectory) self.job.addChild(task) ############### task 2 ########### task = author.Task(title="Copy Project Locally", service="PixarRender") copyin = author.Command(argv=[ "scp", "%s:%s" % (self.centralworkarea, self.mayaprojectpath), "%s:%s" % (self.localhost, self.localworkarea) ]) task.addCommand(copyin) self.job.addChild(task) ############### task 3 ############## task = author.Task(title="Rendering", service="PixarRender") if ((self.endframe - self.startframe) < self.framechunks): self.framechunks = 1 chunkend = self.endframe else: chunkend = self.startframe + self.framechunks chunkstart = self.startframe while (self.endframe >= chunkstart): if chunkend >= self.endframe: chunkend = self.endframe render = author.Command(argv=[ "mayabatch", self.options, "-proj", self.mayaprojectpath, "-start", "%s" % (chunkstart), "-end", "%s" % (chunkend), "-by", self.byframe, "-rd", self.renderdirectory, "-im", self.imagetemplate, "-r", self.renderer, self.options, self.__mayascenefullpath ]) task.addCommand(render) chunkstart = chunkend + 1 chunkend = chunkend + self.framechunks self.job.addChild(task) ############### task 4 ############### task = author.Task(title="Copy Project Back", service="PixarRender") copyout = author.Command(argv=[ "scp", "%s:%s" % (self.localhost, self.localworkarea), "%s:%s" % (self.centralworkarea, self.mayaprojectpath) ]) task.addCommand(copyout) self.job.addChild(task) print "\n{}".format(self.job.asTcl())
def jobs_to_task(jobs, parent_task=None, wait_for_task=None): """ converts a job dependency representation to a single task dependency Recursively adds a Job's main task to a given parent task. This allows you to use the usual tuple vs list syntax to describe a dependency. Args: jobs (:obj:`list` or `tuple` :obj:`Job`): serial/parallel job dependency representation Example: [Job1, Job2] - Job1's root task runs parallel to Job2's root task (Job1, Job2) - Job2's root task runs after Job1's root task [Job1, [Job2, Job3]] - Job1's root task runs parallel to Job2's root task & Job3's root task, but Job3's root task starts when Job2's root task finishes [Job1, (Job2, Job3)] - Job3's root task runs after Job2's root task, Job2's root task runs parallel to Job1's root task parent_task (:obj: `Task`): the parent task that will change recursively root_task (:obj: `Task`): the root task that will represent the main handle for the created dependency Returns: Task: the root path holding the generated dependency """ if not parent_task: root_task = author.Task({}, title="root", id=str(uuid.uuid4())) jobs_to_task(jobs, parent_task=root_task) return root_task if isinstance(jobs, tuple): _serialtask = author.Task({}, serialsubtasks=True, title="serial", id=str(uuid.uuid4())) parent_task.addChild(_serialtask) parent_task = _serialtask elif isinstance(jobs, list): _paralleltask = author.Task({}, title="parallel", id=str(uuid.uuid4())) parent_task.addChild(_paralleltask) parent_task = _paralleltask for job_or_jobs in jobs: if isinstance(job_or_jobs, (tuple, list)): last_task = jobs_to_task(job_or_jobs, parent_task=parent_task, wait_for_task=wait_for_task) if parent_task.title == "serial": wait_for_task = last_task else: # in case we use `append_instances=True` for dynamic expansions... # ensure we properly reference the root task of the prior job and append the instance # to all commandtasks that don't have any children if job_or_jobs.append_instances and wait_for_task: tasks = [ _ for _ in job_or_jobs.flat_hierarchy["tasks"] if _.attributeByName.get("cmds") and not _.subtasks ] for task in tasks: instance = author.Instance(title=wait_for_task.id) task.addChild(instance) # for some reason addChild() doesn't have an effect parent_task.subtasks.append(job_or_jobs.task) if parent_task.title == "serial": wait_for_task = job_or_jobs.task return parent_task
def generate_denoise_tasks(self, start, last, by): tasktitle = "Denoiser Renders" parent_task = author.Task() parent_task.title = tasktitle rm = self.bl_scene.renderman denoise_options = [] if rm.denoise_cmd != '': denoise_options.append(rm.denoise_cmd) if rm.denoise_gpu: denoise_options.append('--override gpuIndex 0 --') # any cross frame? do_cross_frame = False dspys_dict = display_utils.get_dspy_dict(self.rman_scene, expandTokens=False) for dspy, params in dspys_dict['displays'].items(): if not params['denoise']: continue if params['denoise_mode'] == 'crossframe': do_cross_frame = True break if start == last: do_cross_frame = False if do_cross_frame: # for crossframe, do it all in one task cur_frame = self.rman_scene.bl_frame_current task = author.Task() task.title = 'Denoise Cross Frame' command = author.Command(local=False, service="PixarRender") command.argv = ["denoise"] command.argv.extend(denoise_options) command.argv.append('--crossframe') command.argv.append('-v') command.argv.append('variance') for frame_num in range(start, last + 1, by): self.rman_render.bl_frame_current = frame_num variance_file = string_utils.expand_string( dspys_dict['displays']['beauty']['filePath'], frame=frame_num, asFilePath=True) for dspy, params in dspys_dict['displays'].items(): if not params['denoise']: continue if dspy == 'beauty': command.argv.append(variance_file) else: command.argv.append(variance_file) aov_file = string_utils.expand_string( params['filePath'], frame=frame_num, asFilePath=True) command.argv.append(aov_file) task.addCommand(command) parent_task.addChild(task) else: # singlframe cur_frame = self.rman_scene.bl_frame_current for frame_num in range(start, last + 1, by): self.rman_render.bl_frame_current = frame_num variance_file = string_utils.expand_string( dspys_dict['displays']['beauty']['filePath'], frame=frame_num, asFilePath=True) for dspy, params in dspys_dict['displays'].items(): if not params['denoise']: continue if params['denoise_mode'] != 'singleframe': continue task = author.Task() task.title = 'Denoise Frame %d' % frame_num command = author.Command(local=False, service="PixarRender") command.argv = ["denoise"] command.argv.extend(denoise_options) if dspy == 'beauty': command.argv.append(variance_file) else: command.argv.append(variance_file) aov_file = string_utils.expand_string( params['filePath'], frame=frame_num, asFilePath=True) command.argv.append(aov_file) task.addCommand(command) parent_task.addChild(task) self.rman_render.bl_frame_current = cur_frame return parent_task
def build(self): """ main build of job :return: """ self.__mayascenefullpath = "%s/%s" % (self.mayaprojectpath, self.mayascene) self.__mayascenebase = os.path.splitext(self.mayascene)[0] env = self.fj.author.Command(argv=["printenv"]) pwd = self.fj.author.Command(argv=["pwd"]) task1 = author.Task(title="Make output directory", service="PixarRender") makediectory = author.Command( argv=["mkdir", os.path.join(self.mayaprojectpath, "images")]) task1.addCommand(makediectory) self.job.addChild(task1) task2 = author.Task(title="Copy Project Locally", service="PixarRender") copyin = author.Command(argv=[ "scp", "%s:%s" % (self.centralworkarea, self.mayaprojectpath), "%s:%s" % (self.localhost, self.localworkarea) ]) task2.addCommand(copyin) self.job.addChild(task2) if self.renderer == "mr": pass elif self.renderer == "rman": pass elif self.renderer == "maya": pass task3 = author.Task(title="Rendering", service="PixarRender") if (self.endframe - self.startframe) < self.framechunks: self.framechunks = 1 chunkend = self.endframe else: chunkend = self.startframe + self.framechunks chunkstart = self.startframe while self.endframe >= chunkstart: if chunkend >= self.endframe: chunkend = self.endframe commonargs = [ "Render", "-r", self.renderer, "-proj", self.mayaprojectpath, "-start", "%s" % chunkstart, "-end", "%s" % chunkend, "-by", self.byframe, "-rd", self.renderdirectory, "-im", self.imagetemplate ] rendererspecificargs = [ self.expandArgumentString(self.options), self.__mayascenefullpath ] finalargs = commonargs + rendererspecificargs render = author.Command(argv=finalargs) task3.addCommand(render) chunkstart = chunkend + 1 chunkend += self.framechunks self.job.addChild(task3) # ############## task 4 ############### task4 = author.Task(title="Copy Project Back", service="PixarRender") copyout = author.Command(argv=[ "scp", "%s:%s" % (self.localhost, self.localworkarea), "%s:%s" % (self.centralworkarea, self.mayaprojectpath) ]) task4.addCommand(copyout) self.job.addChild(task4) print "\n{}".format(self.job.asTcl())
def makeJob(entries): for entry in entries: field = entry[0] text = entry[1].get() print('%s: "%s"' % ( field, text)) mayaversion = entries[0][1].get() mayaprojectpath = entries[1][1].get() mayascene = entries[2][1].get() mayascenefullpath = "%s/%s" % (mayaprojectpath, mayascene) mayascenebase = os.path.splitext(mayascene)[0] startframe = (entries[3][1].get()) endframe = (entries[4][1].get()) byframe = (entries[5][1].get()) chunks = (entries[6][1].get()) options = (entries[7][1].get()) job = author.Job(title="MayaBatch Render Job", priority=100, envkey=["maya%s" % mayaversion], service="PixarRender") task = author.Task(title="Copy Project Locally", service="PixarRender") copyin = author.Command(argv=["scp", "remote:%s" % (mayaprojectpath), "/Volume/localrender/"]) task.addCommand(copyin) job.addChild(task) task = author.Task(title="Make output directory", service="PixarRender") makediectory = author.Command(argv=["mkdir", "%s/%s/%s" % (mayaprojectpath, "images", mayascenebase)]) task.addCommand(makediectory) job.addChild(task) if ( int(chunks) > (int(endframe) - int(startframe)) ): chunk = 1 framesperchunk = (int(endframe) - int(startframe) + 1) remainder = 0 else: (framesperchunk, remainder) = divmod((int(endframe) - int(startframe) + 1), int(chunks)) chunk = chunks # print int(startframe),int(endframe),int(chunk),int(chunks),int(remainder),int(framesperchunk) task = author.Task(title="Rendering", service="PixarRender") for i in range(0, int(chunk)): sf = (int(startframe) + (i * int(framesperchunk)) ) ef = (int(startframe) + (i * int(framesperchunk)) + int(framesperchunk) - 1 ) if (ef >= int(endframe) or (i == int(chunks) - 1)): ef = int(endframe) render = author.Command(argv=["mayabatch", options, "-proj", mayaprojectpath, "-start", "%s" % (sf), "-end", "%s" % (ef), "-by", byframe, mayascenefullpath]) task.addCommand(render) job.addChild(task) task = author.Task(title="Copy Project Back", service="PixarRender") copyout = author.Command(argv=["scp", "/local/file.tif", "remote:/path/file.tif"]) task.addCommand(copyout) job.addChild(task) print "\n{}".format(job.asTcl())
def export(self): self.close() # Get user, project, and time info so we can make a temp folder user = self.environment.get_current_username() projectName = self.project.get_name().lower() time_now = datetime.datetime.now() #Make a temp folder for the rib files based on the user and the current time ribDir = self.project.get_project_dir( ) + '/ribs/' + user + '_' + time_now.strftime('%m%d%y_%H%M%S') print 'ribDir', ribDir, ' renderNodes size: ', len(self.renderNodes) os.makedirs(ribDir) # Sanitize job title title = re.sub(r'[{}"\']', '', str(self.jobName.text())).strip(' \t\n\r') if len(title) == 0: title = self.empty_text numCores = int( re.sub(r'[{}"\']', '', str(self.numCores.text())).strip(' \t\n\r')) if numCores < 1: numCores = 1 # This job we send to tractor job = author.Job() job.title = title job.priority = self.priority.currentIndex() path = '/opt/pixar/RenderManProServer-21.5/bin/' job.envkey = [ 'setenv PATH=' + path + ' RMANTREE=/opt/pixar/RenderManProServer-21.5' ] job.service = 'PixarRender' job.comment = 'Spooled by ' + user # Loop through each frame of our nodes and create frame tasks and append it to the job script for index, node in enumerate(self.renderNodes): # Make sure this node was selected for export print node.name() if self.select.item(index).isSelected(): name = node.name() validFrameRange = node.parm('trange').eval() if validFrameRange == 0: start = int(hou.frame()) end = int(hou.frame()) step = 1 else: start = int(node.parm('f1').eval()) end = int(node.parm('f2').eval()) step = int(node.parm('f3').eval()) task = author.Task() task.title = '%s [%d-%d]' % (name, start, end) oldOutputMode = node.parm('rib_outputmode').eval() try: oldDiskFile = node.parm('soho_diskfile').expression() useExpression = True print 'We are getting rid of expressiion' except: oldDiskFile = node.parm('soho_diskfile').eval() useExpression = False print 'we didn\'t get rid of them' # Activate rib output node.parm('rib_outputmode').set(True) node.parm('soho_diskfile').deleteAllKeyframes() node.parm('soho_diskfile').set(ribDir + ('/%s_$F04.rib' % name)) print 'start rib making' script = os.path.join(self.project.get_project_dir(), 'byu-pipeline-tools', 'houdini-tools', 'parallelRibs', 'taskDistribution.sh') subprocess.call([ 'sh', script, str(start), str(end), str(node.path()), str(saveHipRenderCopy()), str(numCores) ]) print 'finish rib making' # Loop through every frame in framerange for frame in range(start, end + 1, step): subtask = author.Task() subtask.title = 'Frame %04d' % (frame) ribFile = '%s/%s_%04d.rib' % (ribDir, name, frame) print 'Here is the rib file ', ribFile # Commands for Debugging cmdPATH = author.Command() cmdPATH.argv = ['echo', '${PATH}'] cmdRMANTREE = author.Command() cmdRMANTREE.argv = ['echo', '${RMANTREE}'] printenv = author.Command() printenv.argv = ['printenv'] # subtask.addCommand(cmdPATH) # subtask.addCommand(cmdRMANTREE) # subtask.addCommand(printenv) # Real Commands command = author.Command() command.argv = ['prman', '-progress', ribFile] command.service = 'PixarRender' subtask.addCommand(command) task.addChild(subtask) job.addChild(task) # Restore rib output node.parm('soho_outputmode').set(oldOutputMode) if useExpression: node.parm('soho_diskfile').setExpression(oldDiskFile) else: node.parm('soho_diskfile').set(oldDiskFile) command = author.Command() command.argv = ['rm', '-rf', ribDir] job.addCleanup(command) # print 'This is the new job script \n', job.asTcl() # Attempt to spool job, with the option to keep trying choice = True while choice: try: job.spool() message_gui.info('Job sent to Tractor!') break except Exception as err: choice = message_gui.yes_or_no( 'We ran into this problem while spooling the job:\nWould you like to try again?', details=str(err), title='Continue?') #Cleanup ifd files, if they didn't want to retry if not choice: shutil.rmtree(ribDir)
def build(self): ''' Main method to build the job :return: ''' # ################ 0 JOB ################ self.job = self.farmjob.author.Job(title="RM: {} {} {}-{}".format( self.renderusername,self.scenename,self.startframe,self.endframe), priority=10, envkey=[self.envkey_rfm,"ProjectX", "TYPE={}".format(self.envtype), "SHOW={}".format(self.envshow), "PROJECT={}".format(self.envproject), "SCENE={}".format(self.envscene), "SCENENAME={}".format(self.scenebasename)], metadata="user={} username={} usernumber={}".format( self.user, self.renderusername,self.renderusernumber), comment="LocalUser is {} {} {}".format(self.user,self.renderusername,self.renderusernumber), projects=[str(self.projectgroup)], tier=str(self.farmjob.getdefault("renderjob","rendertier")), tags=["theWholeFarm", ], service="") # ############## 0 ThisJob ################# task_thisjob = self.farmjob.author.Task(title="Renderman Job") task_thisjob.serialsubtasks = 1 # ############## 1 PREFLIGHT ############## task_preflight = self.farmjob.author.Task(title="Preflight") task_preflight.serialsubtasks = 1 task_thisjob.addChild(task_preflight) task_generate_rib_preflight = self.farmjob.author.Task(title="Generate RIB Preflight") command_ribgen = self.farmjob.author.Command(argv=["maya","-batch","-proj", self.mayaprojectpath, "-command", "renderManBatchGenRibForLayer {layerid} {start} {end} {phase}".format( layerid=0, start=self.startframe, end=self.endframe, phase=1), "-file", self.mayascenefilefullpath], tags=["maya", "theWholeFarm"], atleast=int(self.threads), atmost=int(self.threads), service="RfMRibGen") task_generate_rib_preflight.addCommand(command_ribgen) task_preflight.addChild(task_generate_rib_preflight) task_render_preflight = author.Task(title="Render Preflight") command_render_preflight = author.Command(argv=[ "prman","-t:{}".format(self.threads), "-Progress", "-recover", "%r", "-checkpoint", "5m", "-cwd", self.mayaprojectpath, "renderman/{}/rib/job/job.rib".format(self.scenebasename)], tags=["prman", "theWholeFarm"], atleast=int(self.threads), atmost=int(self.threads), service="PixarRender") task_render_preflight.addCommand(command_render_preflight) task_preflight.addChild(task_render_preflight) # ############## 3 RIBGEN ############## task_render_allframes = self.farmjob.author.Task(title="ALL FRAMES {}-{}".format(self.startframe, self.endframe)) task_render_allframes.serialsubtasks = 1 task_ribgen_allframes = self.farmjob.author.Task(title="RIB GEN {}-{}".format(self.startframe, self.endframe)) # divide the frame range up into chunks _totalframes=int(self.endframe-self.startframe+1) _chunks = int(self.ribgenchunks) _framesperchunk=_totalframes if _chunks < _totalframes: _framesperchunk=int(_totalframes/_chunks) else: _chunks=1 # loop thru chunks for i,chunk in enumerate(range(1,_chunks+1)): _offset=i*_framesperchunk _chunkstart=(self.startframe+_offset) _chunkend=(_offset+_framesperchunk) logger.info("Chunk {} is frames {}-{}".format(chunk, _chunkstart, _chunkend)) if chunk == _chunks: _chunkend = self.endframe task_generate_rib = author.Task(title="RIB GEN chunk {} frames {}-{}".format( chunk, _chunkstart, _chunkend )) command_generate_rib = author.Command(argv=[ "maya", "-batch", "-proj", self.mayaprojectpath, "-command", "renderManBatchGenRibForLayer {layerid} {start} {end} {phase}".format( layerid=0, start=_chunkstart, end=_chunkend, phase=2), "-file", self.mayascenefilefullpath], tags=["maya", "theWholeFarm"], atleast=int(self.threads), atmost=int(self.threads), service="RfMRibGen") task_generate_rib.addCommand(command_generate_rib) task_ribgen_allframes.addChild(task_generate_rib) task_render_allframes.addChild(task_ribgen_allframes) # ############### 4 RENDER ############## task_render_frames = self.farmjob.author.Task(title="RENDER Frames {}-{}".format(self.startframe, self.endframe)) task_render_frames.serialsubtasks = 0 for frame in range(self.startframe, (self.endframe + 1), self.byframe): _imgfile = "{proj}/{scenebase}.{frame:04d}.{ext}".format( proj=self.renderdirectory, scenebase=self.scenebasename, frame=frame, ext=self.outformat) _statsfile = "{proj}/rib/{frame:04d}/{frame:04d}.xml".format( proj=self.rendermanpath, frame=frame) _ribfile = "{proj}/rib/{frame:04d}/{frame:04d}.rib".format( proj=self.rendermanpath, frame=frame) task_render_rib = self.farmjob.author.Task(title="RENDER Frame {}".format(frame), preview="sho {}".format(_imgfile), metadata="statsfile={} imgfile={}".format(_statsfile, _imgfile)) commonargs = ["prman", "-cwd", self.mayaprojectpath] rendererspecificargs = [] # ################ handle image resolution formats ########### if self.resolution == "720p": self.xres, self.yres = 1280, 720 rendererspecificargs.extend(["-res", "%s" % self.xres, "%s" % self.yres]) elif self.resolution == "1080p": self.xres, self.yres = 1920, 1080 rendererspecificargs.extend(["-res", "%s" % self.xres, "%s" % self.yres]) elif self.resolution == "540p": self.xres, self.yres = 960, 540 rendererspecificargs.extend(["-res", "%s" % self.xres, "%s" % self.yres]) elif self.resolution == "108p": self.xres, self.yres = 192, 108 rendererspecificargs.extend(["-res", "%s" % self.xres, "%s" % self.yres]) if self.rendermaxsamples != "FROMFILE": rendererspecificargs.extend([ "-maxsamples", "{}".format(self.rendermaxsamples) ]) # if self.threadmemory != "FROMFILE": # rendererspecificargs.extend([ "-memorylimit", "{}".format(self.threadmemory) ]) rendererspecificargs.extend([ # "-pad", "4", # "-memorylimit", self.threadmemory, # mb "-t:{}".format(self.threads), "-Progress", "-recover", "%r", "-checkpoint", "5m", "-statslevel", "2", #"-maxsamples", "{}".format(self.rendermaxsamples) # override RIB ray trace hider maxsamples # "-pixelvariance","3" # override RIB PixelVariance # "-d", "" # dispType # -version : print the version # "-progress ", : print percent complete while rendering # -recover [0|1] : resuming rendering partial frames # -t:X : render using 'X' threads # -woff msgid,... : suppress error messages from provided list # -catrib file : write RIB to 'file' without rendering # -ascii : write RIB to ASCII format file # -binary : write RIB to Binary format file # -gzip : compress output file # -capture file : write RIB to 'file' while rendering # -nobake : disallow re-render baking # -res x y[:par] : override RIB Format # -crop xmin xmax ymin ymax # : override RIB CropWindow # -maxsamples i : override RIB ray trace hider maxsamples # -pixelvariance f : override RIB PixelVariance # -d dispType : override RIB Display type # -statsfile f : override RIB stats file & level (1) # -statslevel i : override RIB stats level # -memorylimit f : override RIB to set memory limit ratio # -checkpoint t[,t] : checkpoint interval and optional exit time ]) userspecificargs = [ utils.expandargumentstring(self.options),"{}".format(_ribfile)] finalargs = commonargs + rendererspecificargs + userspecificargs command_render = self.farmjob.author.Command(argv=finalargs, #envkey=[self.envkey_prman], tags=["prman", "theWholeFarm"], atleast=int(self.threads), atmost=int(self.threads), service="PixarRender") task_render_rib.addCommand(command_render) task_render_frames.addChild(task_render_rib) task_render_allframes.addChild(task_render_frames) task_thisjob.addChild(task_render_allframes) # ############## 5 PROXY ############### if self.makeproxy: ''' rvio cameraShape1/StillLife.####.exr -v -fps 25 -rthreads 4 -outres 1280 720 -out8 -leader simpleslate "UTS" "Artist=Anthony" "Show=Still_Life" "Shot=Testing" -overlay frameburn .4 1.0 30.0 -overlay matte 2.35 0.3 -overlay watermark "UTS 3D LAB" .2 -outgamma 2.2 -o cameraShape1_StillLife.mov ''' #### making proxys with rvio _outmov = "{}/movies/{}.mov".format(self.mayaprojectpath, self.scenebasename,utils.getnow()) _inseq = "{}.####.exr".format(self.scenebasename) #cameraShape1/StillLife.####.exr" _directory = "{}/renderman/{}/images".format(self.mayaprojectpath, self.scenebasename) _seq = os.path.join(_directory, _inseq) try: utils.makedirectoriesinpath(os.path.dirname(_outmov)) except Exception, err: logger.warn(err) try: _option1 = "-v -fps 25 -rthreads {threads} -outres {xres} {yres} -t {start}-{end}".format( threads="4", xres="1280", yres = "720", start=self.startframe, end=self.endframe) _option2 = "-out8 -outgamma 2.2" _option3 = "-overlay frameburn 0.5 1.0 30 -leader simpleslate UTS_BDES_ANIMATION Type={} Show={} Project={} File={} Student={}-{} Group={} Date={}".format( self.envtype, self.envshow, self.envproject, self.scenebasename, self.user, self.renderusername, self.projectgroup, self.thedate) _output = "-o %s" % _outmov _rvio_cmd = [ utils.expandargumentstring("rvio %s %s %s %s %s" % (_seq, _option1, _option2, _option3, _output)) ] task_proxy = self.farmjob.author.Task(title="Proxy Generation") proxycommand = author.Command(argv=_rvio_cmd, service="Transcoding", tags=["rvio", "theWholeFarm"], envkey=["rvio"]) task_proxy.addCommand(proxycommand) task_thisjob.addChild(task_proxy) except Exception, proxyerror: logger.warn("Cant make a proxy {}".format(proxyerror))
def _render_to_farm(self): import tractor.api.author as author start_frame = int(self.ui.start_frame.text()) end_frame = int(self.ui.end_frame.text()) file_name = FarmAPI.GetKatanaFileName() temp_file = self._get_temp_file(str(file_name)) if not os.path.exists(os.path.dirname(temp_file)): os.makedirs(os.path.dirname(temp_file)) status = shutil.copyfile(file_name, temp_file) for node in self.selected_nodes: job = author.Job() #job.title = '[Katana]' + file_name.split(".")[0].split("/") job.service = "Linux64" job.priority = 50 file_title = file_name.split(".")[0].split("/")[-1] project_name = self._app.context.project['name'] user_name = self._app.context.user['name'] user_id = os.environ['USER'] select_node = str(node.getName()) temp = "] [" title = [] title.append(user_name) title.append(project_name) title.append(file_title) title.append(select_node) title.append("%d - %d" % (start_frame, end_frame)) title = temp.join(title) title = "[" + title + "]" job.title = str(title) for frame in range(start_frame, end_frame + 1): task = author.Task(title=str(frame)) if os.environ['REZ_KATANA_VERSION'] == "3.1v2": command = [ 'rez-env', 'katana-3.1v2', 'renderman-22', 'usd-19.03', 'yeti', '--', 'katana' ] else: command = [ 'rez-env', 'katana-2.6v4', 'renderman-21.8', 'usd-19.03', 'yeti-2.2.9', '--', 'katana' ] command.append("--batch") command.append("--katana-file=%s" % temp_file) command.append("--render-node=%s" % node.getName()) command.append(str("--t=%d-%d" % (frame, frame))) command = author.Command(argv=command) task.addCommand(command) job.addChild(task) job.spool(hostname="10.0.20.82", owner=user_id) self.close() return