def performPostDialogChecks(self, fields):
    # check all outputs, and if there are some files on disc already exist
    results = {}
    for field in fields:
      results[field['name']] = field['value']

    if results.get('overwrite', False):
      return True

    scene = self.__app.ActiveProject.ActiveScene
    currentPass = scene.ActivePass
    frameBuffers = currentPass.FrameBuffers

    # we need 5 padding...
    self.__app.SetValue("Passes.RenderOptions.FramePadding", 5)

    existingFiles = []
    for i in range(frameBuffers.Count):
      fb = frameBuffers(i)
      if not fb.Parameters.GetItem('Enabled').Value:
        continue

      # for now let's check last and first frame
      times = [results['framestart'], results['frameend']]
      for t in times:
        path = fb.GetResolvedPath(t)
        path = zk_uncFromDrivePath(path)
        if os.path.exists(path):
          existingFiles += [path]
    if len(existingFiles) > 0:
      msgBox = QtGui.QMessageBox()
      msgBox.setText("Are you sure?")
      text = "There are already files on disc which will be\noverwritten if you submit this job!\n\n%s\n\nThis info has been copied to the clipboard." % '\n'.join(existingFiles)
      clipboard = QtGui.QApplication.clipboard()
      clipboard.setText(text)
      msgBox.setInformativeText(text)
      msgBox.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
      msgBox.setDefaultButton(QtGui.QMessageBox.Ok)
      ret = msgBox.exec_()
      return ret == QtGui.QMessageBox.Ok

    return True
  def createJobFramesAndOutput(self, fields, connection, bracket, project, input):

    #persist all standard changes in scene....
    prop = self.__app.ActiveSceneRoot.Properties.GetItem('zookeeper')
    if not prop:
      self.__app.AddProp("Custom_parameter_list", "Scene_Root", "", "zookeeper", "")
      self.__app.SIAddCustomParameter("Scene_Root.zookeeper", "projectid", "siString", "", 0, 1, "", 4, 0, 1, "", "")
      self.__app.SIAddCustomParameter("Scene_Root.zookeeper", "mincores", "siString", "", 0, 1, "", 4, 0, 1, "", "")
      self.__app.SIAddCustomParameter("Scene_Root.zookeeper", "minramgb", "siString", "", 0, 1, "", 4, 0, 1, "", "")
      self.__app.SIAddCustomParameter("Scene_Root.zookeeper", "mingpuramgb", "siString", "", 0, 1, "", 4, 0, 1, "", "")
      self.__app.SIAddCustomParameter("Scene_Root.zookeeper", "packagesize", "siString", "", 0, 1, "", 4, 0, 1, "", "")
      prop = self.__app.ActiveSceneRoot.Properties.GetItem('zookeeper')

    if prop:
      for f in fields:
        param = prop.Parameters.GetItem(f['name'])
        if param:
          param.Value = f['value']

    results = {}
    for field in fields:
      results[field['name']] = field['value']

    scene = self.__app.ActiveProject.ActiveScene
    currentPass = scene.ActivePass
    frameBuffers = currentPass.FrameBuffers

    framestart = results['framestart']
    frameend = results['frameend']
    framestep = results['framestep']
    packagesize = results['packagesize']
    capturejob = results.get('capturejob', False)
    highprio_firstlast = results['highprio_firstlast']

    # submit all external files
    xsiFiles = scene.ExternalFiles
    for i in range(xsiFiles.Count):
      xsiFile = xsiFiles(i)
      resolvedPath = xsiFile.ResolvedPath

      # invalid rigid body cache
      if resolvedPath.lower().endswith('rigidbodycache.xsi'):
        continue

      resolution = -1
      if xsiFile.FileType == 'Models':
        param = xsiFile.Owners(0)
        model = param.Parent
        if param.Name == 'res'+str(model.active_resolution.value):
          resolution = model.active_resolution.value
      f = zookeeper.zkDB.zkExternalFile.getOrCreateByProjectAndPaths(self.connection, project.id, xsiFile.Path, xsiFile.ResolvedPath, type = xsiFile.FileType, resolution = resolution)
      if f.id is None:
        self.__app.LogMessage('Error: Could not create external file for '+xsiFile.Path)

    # redshift IES profile files
    objects = self.__app.FindObjects('', '{6495C5C1-FD18-474E-9703-AEA66631F7A7}')
    for i in range(objects.Count):
      o = objects(i)
      if not o.Name.lower() == 'redshift_ies':
        continue
      iesPath = str(o.profileString.Value)
      resolvedPath = iesPath
      if not os.path.exists(iesPath):
        resolvedPath = os.path.join(self.__app.ActiveProject.Path, resolvedPath)
      f = zookeeper.zkDB.zkExternalFile.getOrCreateByProjectAndPaths(self.connection, project.id, iesPath, resolvedPath, type = 'IESProfiles', resolution = -1)
      if f.id is None:
        self.__app.LogMessage('Error: Could not create external file for '+iesPath)

    if capturejob:

      job = zookeeper.zkDB.zkJob.createNew(self.connection)
      job.project = project
      job.name = results['jobname']+' capture'
      job.input = input
      job.type = 'CAPTURE'
      self.decorateJobWithDefaults(fields, job)
      bracket.push(job)

      # make a single frame for the capture movie
      frame = zookeeper.zkDB.zkFrame.createNew(self.connection)
      frame.job = job
      frame.time = framestart
      frame.timeend = frameend
      frame.priority = 100
      job.pushFrameForSubmit(frame)

      # create a single output for the movie
      mainBuffer = frameBuffers(0)
      capturePath = str(mainBuffer.GetResolvedPath(framestart))
      capturePath = capturePath.rpartition('.')[0]
      capturePath += '.mov'
      output = zookeeper.zkDB.zkOutput.createNew(self.connection)
      output.frame = frame
      output.name = mainBuffer.Name
      output.path = zk_uncFromDrivePath(capturePath)
      frame.pushOutputForSubmit(output)

    passes = scene.Passes
    for i in range(passes.Count):
      passObj = passes(i)
      sceneName = str(scene.Name)
      passName = str(passObj.Name)

      if not results.get('pass_'+str(passObj.Name), False):
        continue

      job = zookeeper.zkDB.zkJob.createNew(self.connection)
      job.project = project
      job.name = '%s|%s' % (sceneName, passName)
      job.input = input
      job.type = 'ALL'
      self.decorateJobWithDefaults(fields, job)
      bracket.push(job)

      packageoffset = 0
      package = 0

      # --- edit JPB --- take line out before push ---
      # add a modulo for every 10th frame to prioritize
      fm = 0
      # --- edit JPB --- take line out before push ---

      for f in range(framestart, frameend+1, framestep):

        self.__app.LogMessage('Submitting frame '+str(f))

        if packageoffset % packagesize == 0:
          package = package + 1
        packageoffset = packageoffset + 1

        frame = zookeeper.zkDB.zkFrame.createNew(self.connection)
        frame.job = job
        frame.time = f

        # --- edit JPB --- take line out before push ---
        # modulo every 10th frame
        if fm%10 == 0:
          frame.priority = 75
        else:
          frame.priority = 50
        # --- edit JPB --- take line out before push ---

        frame.package = package
        if highprio_firstlast:
          if f == framestart or f == frameend:
            frame.priority = 75
            #frame.package = 1
        job.pushFrameForSubmit(frame)

        fm+=1
示例#3
0
  def submitWithDialog(self):

    zkSubmitter.__app = zookeeper.zkUI.zkApp()

    # check input and external file paths
    brokenFiles = []
    inputpath = self.getInputPath()
    networkInputPath = zk_uncFromDrivePath(inputpath)
    if not self.validatePath(inputpath, shouldExist=True):
      brokenFiles += [{'path': inputpath, 'group': 'Scenes'}]
    else:
      # check if there is already a job logged for this
      jobName = self.getJobDefaultName()
      existingJob = zookeeper.zkDB.zkJob.getByCondition(
        self.__conn,
        condition = 'job_inputid = input_id AND job_name = %s AND input_path = %s AND job_type != \'DELETED\'' % (repr(str(jobName)), repr(str(networkInputPath))),
        additionalTables = ['input']
        )
      if existingJob:
        msgBox = QtGui.QMessageBox()
        msgBox.setText("Are you sure?")
        msgBox.setInformativeText("There's already a job (%s, %d) on the queue with this input path!" % (existingJob.name, existingJob.id))
        msgBox.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
        msgBox.setDefaultButton(QtGui.QMessageBox.Ok)
        ret = msgBox.exec_()
        if ret == QtGui.QMessageBox.Cancel:
          return

    externalfiles = self.getExternalFilePaths()
    for f in externalfiles:
      if not self.validatePath(f['path'], shouldExist=f.get('exist', True)):
        brokenFiles += [f]

    if len(brokenFiles) > 0:
      text = "Some paths are not accessible by other machines on the network.\n"
      text += "Submitting a job is not possible until this is fixed\n."
      for brokenFile in brokenFiles:
        text += '\n%s: %s' % (brokenFile.get('group', 'file'), brokenFile['path'])
      text += "\n\nThis info has been copied to the clipboard."

      clipboard = QtGui.QApplication.clipboard()
      clipboard.setText(text)

      QtGui.QMessageBox.warning(None, 'ZooKeeper Warning', text)
      return

    fields = []
    fields += [{'name': 'dcc', 'label': 'DCC', 'value': self.getDCCName(), 'type': 'str', 'readonly': True, 'tooltip': 'The name of the DCC'}]
    fields += [{'name': 'dccversion', 'label': 'DCC Version', 'value': self.getDCCVersion(), 'type': 'str', 'readonly': True, 'tooltip': 'The version of the DCC'}]
    fields += [{'name': 'renderer', 'label': 'Renderer', 'value': self.getRendererName(), 'type': 'str', 'readonly': True, 'tooltip': 'The name of the renderer'}]
    fields += [{'name': 'rendererversion', 'label': 'Renderer Version', 'value': self.getRendererVersion(), 'type': 'str', 'readonly': True, 'tooltip': 'The version of the renderer'}]

    # ensure that we have one project at least!
    pairs = zookeeper.zkDB.zkProject.getNameComboPairs(self.__conn, condition = 'project_type != \'DELETED\'')
    if len(pairs) == 0:
      self.createNewProjectWithDialog()
      pairs = zookeeper.zkDB.zkProject.getNameComboPairs(self.__conn, condition = 'project_type != \'DELETED\'')
      if len(pairs) == 0:
        return

    projectid = pairs[0][0]
    projectname = self.getProjectDefaultName()
    if projectname:
      for pair in pairs:
        if pair[1] == projectname:
          projectid = pair[0]
          break

    fields += [{'name': 'projectid', 'label': 'Project', 'value': projectid, 'type': 'combo', 'comboitems': pairs, 'tooltip': "The name of the project"}]
    fields += [{'name': 'jobname', 'label': 'Job', 'value': self.getJobDefaultName(), 'type': 'str', 'tooltip': "The name of the job", 'readonly': True}]
    fields += [{'name': 'jobpriority', 'label': 'Priority', 'value': 50, 'type': 'int', 'tooltip': "The priority of the job"}]
    fields += [{'name': 'mincores', 'label': 'Minimum Cores', 'value': 4, 'type': 'int', 'tooltip': "The minimum of CPU cores a client machine requires."}]
    fields += [{'name': 'minramgb', 'label': 'Minimum RAM', 'value': 8, 'type': 'int', 'tooltip': "The minimum of RAM (GB) a client machine requires."}]
    fields += [{'name': 'mingpuramgb', 'label': 'Minimum GPU RAM', 'value': 2, 'type': 'int', 'tooltip': "The minimum of GPU RAM (GB) a client machine requires."}]
    fields += [{'name': 'overwrite', 'label': 'Overwrite files', 'value': False, 'type': 'bool', 'tooltip': "If checked the delivery will overwrite existing frames without checking."}]
    fields += self.getExtraFields()

    def onAccepted(fields):

      if not self.performPostDialogChecks(fields):
        return

      results = {}
      for field in fields:
        results[field['name']] = field['value']

      b = zookeeper.zkDB.zkBracket(self.__conn)
      p = zookeeper.zkDB.zkProject.getById(self.__conn, results['projectid'])

      i = zookeeper.zkDB.zkInput.createNew(self.__conn)
      i.path = networkInputPath
      b.push(i)
      
      self.createJobFramesAndOutput(fields, self.__conn, b, p, i)
      b.write()

      msgBox = QtGui.QMessageBox()
      msgBox.setText("ZooKeeper")
      msgBox.setInformativeText('Job "%s" submitted.' % results['jobname'])
      msgBox.setStandardButtons(QtGui.QMessageBox.Ok)
      msgBox.setDefaultButton(QtGui.QMessageBox.Ok)
      msgBox.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
      msgBox.exec_()

    dialog = zookeeper.zkUI.zkSubmitDialog(fields, onAccepted)
    dialog.exec_()