No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

muster_template.py.txt 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. ''' Muster 8 Generic script template class '''
  2. ''' Import Muster base modules '''
  3. import MClientAPI
  4. import MTemplateAPI
  5. ''' Import Python base lib modules '''
  6. import os.path
  7. import re
  8. ''' Get the template manager singleton '''
  9. manager = MTemplateAPI.MManager.getUniqueClass()
  10. ''' Define a new class derived from MTemplateAPI.MTemplate base class , override required methods '''
  11. class ShellTemplate(MTemplateAPI.MTemplate):
  12. def __init__(self):
  13. MTemplateAPI.MTemplate.__init__(self)
  14. self.setID(2008)
  15. self.setName("Denoise_Noice")
  16. self.setDescription("Denoise with Noice")
  17. self.setTemplateLogic(MTemplateAPI.kTemplateMultiframe)
  18. self.setDefaultPriority(1)
  19. self.setDefaultPools("arnold_16thread")
  20. self.setDefaultExcludedPools("")
  21. self.setMaximumLicenses(0)
  22. self.setEnableAdditionalFlagsField(1)
  23. ''' Submission form items allocation '''
  24. NoiceBin = MTemplateAPI.MTemplateItemFolder("NOICEBIN", "Noice Bin Path", "Specifies the Noice bin Path", "", 0,
  25. 1, 1)
  26. patchRadius = MTemplateAPI.MTemplateItemInteger("PATCHRADIUS", "PatchRadius", "Specify the patch radius", 3, 0,
  27. 0, 1)
  28. searchRadius = MTemplateAPI.MTemplateItemInteger("SEARCHRADIUS", "PatchRadius", "Specify the patch radius", 9,
  29. 0, 0, 1)
  30. variance = MTemplateAPI.MTemplateItemDouble("VARIANCE", "Variance", "Specifies the variance", 0.25, 0, 0, 1)
  31. lightAovString = MTemplateAPI.MTemplateItemString("LIGHTAOVSTRING", "Light AOV String",
  32. "Specifies the AOVs to be denoised. Syntax: -aov aovname1 -aov aovname2 -aov aovname3",
  33. "-aov rgba", 0, 0, 1)
  34. temporalFrames = MTemplateAPI.MTemplateItemInteger("TEMPORALFRAMES", "Temporal Frames",
  35. "Specifies the temporal frames", 0, 0, 0, 1)
  36. denoiseThreads = MTemplateAPI.MTemplateItemInteger("DENOISETHREADS", "Threads", "Specify the denoise threads",
  37. -2, 1, 0, 1)
  38. startFrame = MTemplateAPI.MTemplateItemInteger("NOICESTARTFRAME", "Start frame",
  39. "Specifies the starting frame for the rendering job", 1001, 0, 0,
  40. 1)
  41. endFrame = MTemplateAPI.MTemplateItemInteger("NOICEENDFRAME", "End frame",
  42. "Specifies the ending frame for the rendering job", 1010, 0, 0, 1)
  43. inputFile = MTemplateAPI.MTemplateItemFile("INPUTFILE", "Input File", "Specifies the File to be denoised", "",
  44. 0, 1, 1, "*.exr")
  45. outputFile = MTemplateAPI.MTemplateItemFile("OUTPUTFILE", "Output File", "Specifies the output File", "", 0, 1,
  46. 1, "*.exr")
  47. self.addSubmissionItem(NoiceBin)
  48. self.addSubmissionItem(patchRadius)
  49. self.addSubmissionItem(searchRadius)
  50. self.addSubmissionItem(variance)
  51. self.addSubmissionItem(lightAovString)
  52. self.addSubmissionItem(temporalFrames)
  53. self.addSubmissionItem(denoiseThreads)
  54. self.addSubmissionItem(startFrame)
  55. self.addSubmissionItem(endFrame)
  56. self.addSubmissionItem(inputFile)
  57. self.addSubmissionItem(outputFile)
  58. ''' items mapping to Muster default tags '''
  59. self.addMapping("INPUTFILE", "job_file")
  60. self.addMapping("NOICESTARTFRAME", "start_frame")
  61. self.addMapping("NOICEENDFRAME", "end_frame")
  62. ''' Windows support '''
  63. self.platformWindows.setPlatformEnabled(1)
  64. self.platformWindows.setEnableErrorCheck(1)
  65. self.platformWindows.setEnabledByDefault(1)
  66. self.platformWindows.setDetectionLogic(MTemplateAPI.kProcessChild)
  67. #self.platformWindows.setDetectionLogic(MTemplateAPI.kProcessDirect)
  68. self.platformWindows.setDetectionLogicProcessName("noice.exe")
  69. ''' OSX support '''
  70. self.platformOSX.setPlatformEnabled(0)
  71. self.platformOSX.setEnableErrorCheck(1)
  72. self.platformOSX.setEnabledByDefault(1)
  73. self.platformOSX.setDetectionLogic(MTemplateAPI.kProcessDirect)
  74. applicationPath = MTemplateAPI.MTemplateItemFile("SHELLCMD", "Script interpreter executable",
  75. "Specifies the OS X script executable", "/bin/sh", 0, 0, 1,
  76. "*.exe")
  77. self.platformOSX.addClientConfigurationItem(applicationPath)
  78. ''' Linux support '''
  79. self.platformLinux.setPlatformEnabled(0)
  80. self.platformLinux.setEnableErrorCheck(1)
  81. self.platformLinux.setEnabledByDefault(1)
  82. self.platformLinux.setDetectionLogic(MTemplateAPI.kProcessDirect)
  83. applicationPath = MTemplateAPI.MTemplateItemFile("SHELLCMD", "Script interpreter executable",
  84. "Specifies the Linux script executable", "/bin/sh", 0, 0, 1,
  85. "*.exe")
  86. self.platformLinux.addClientConfigurationItem(applicationPath)
  87. ''' virtual functions overrides '''
  88. def onBuildCommandLine(self, platform, job, chunk, clientTemplatePreferences, instanceNum):
  89. # sequence with sequence string bla.1001.exr
  90. fileIn = job.attributeGetString(manager.resolveMappingToJob(self.getID(), "INPUTFILE"))
  91. fileOut = job.attributeGetString(manager.resolveMappingToJob(self.getID(), "OUTPUTFILE"))
  92. # regex
  93. patternSeq = re.compile(r'\.\d\d\d+\.')
  94. # extract frame substring
  95. frame = patternSeq.findall(fileIn)
  96. # if there are more matches due to non-conform naming
  97. frame = frame[-1]
  98. chunkFrame = "." + str(int(chunk.getStartFrame())) + "."
  99. # replace padding with the startFrame of the chunk
  100. fileIn = fileIn.replace(frame, chunkFrame)
  101. fileOut = fileOut.replace(frame, chunkFrame)
  102. renderCmd = ""
  103. if platform == MClientAPI.kPlatformWindows:
  104. renderCmd += "/c "
  105. renderCmd += "\""
  106. renderCmd += job.attributeGetString("NOICEBIN") + "noice.exe"
  107. renderCmd += " -patchradius %s" % job.attributeGetInt("PATCHRADIUS")
  108. renderCmd += " -searchradius %s" % job.attributeGetInt("SEARCHRADIUS")
  109. renderCmd += " -variance %s" % job.attributeGetFloat("VARIANCE")
  110. renderCmd += " " + job.attributeGetString("LIGHTAOVSTRING") # '-aov aovname1 -aov aovname2'
  111. renderCmd += " -i " + fileIn
  112. renderCmd += " -t " + job.attributeGetString("DENOISETHREADS")
  113. renderCmd += " -ef %s" % job.attributeGetInt("TEMPORALFRAMES")
  114. renderCmd += " -output " + fileOut
  115. renderCmd += "\""
  116. addFlags = job.attributeGetString("ADD_FLAGS")
  117. if len(addFlags) > 0:
  118. renderCmd += " " + addFlags
  119. return renderCmd
  120. def onCheckLog(self, job, chunk, clientTemplatePreferences, log, warnings, errors, silencedWarnings,
  121. silencedErrors):
  122. ## WARNINGS
  123. noWarnings = []
  124. foundset = []
  125. for line in log.splitlines():
  126. if line.lower().find("warning") != -1:
  127. foundset.append(line)
  128. # remove no warning strings
  129. result = [x for x in foundset if not any(y in x for y in noWarnings)]
  130. if len(result) != 0:
  131. return MTemplateAPI.MTemplateError(2, "Warning keyword found",
  132. MTemplateAPI.MTemplateError.kTemplateErrorTypeWarning)
  133. ## ERRORS
  134. if log.lower().find("error") != -1:
  135. return MTemplateAPI.MTemplateError(1, "Error keyword found",
  136. MTemplateAPI.MTemplateError.kTemplateErrorTypeError)
  137. if log.lower().find("no licenses could be found to run this application") != -1:
  138. return MTemplateAPI.MTemplateError(1, "No license available",
  139. MTemplateAPI.MTemplateError.kTemplateErrorTypeError)
  140. return MTemplateAPI.MTemplateError()
  141. def onCheckLogLine(self, job, chunk, clientTemplatePreferences, line, lineNum, warnings, errors, silencedWarnings,
  142. silencedErrors):
  143. return MTemplateAPI.MTemplateError()
  144. def onBuildEnvironment(this, job, chunk, clientTemplatePreferences, existingEnvironment):
  145. return existingEnvironment
  146. def onGetApplicationPath(self, job, chunk, clientTemplatePreferences, pathOut):
  147. platform = MClientAPI.GetPlatform()
  148. if platform == MClientAPI.kPlatformWindows:
  149. pathOut.setString("cmd.exe")
  150. else:
  151. pathOut.setString("/bin/sh")
  152. return MTemplateAPI.MTemplateError()
  153. def onGetApplicationStartingFolder(self, job, chunk, clientTemplatePreferences, pathOut):
  154. pathStart = "c:\\Windows\\System32"
  155. platform = MClientAPI.GetPlatform()
  156. if platform == MClientAPI.kPlatformWindows:
  157. #pathOut.setString(job.attributeGetString("NOICEBIN"))
  158. pathOut.setString(pathStart)
  159. else:
  160. pass
  161. return MTemplateAPI.MTemplateError()
  162. def onCheckForSubframeAdvancingString(self, job, chunk, line):
  163. return 0
  164. def onCheckForSubframeProgress(self, job, chunk, line, progressOut):
  165. return 0
  166. def onCheckExitCode(self, job, chunk, clientTemplatePreferences, exitCode):
  167. if exitCode != 0:
  168. return MTemplateAPI.MTemplateError(exitCode, "%d Exit code different from expected 0 value" % exitCode,
  169. MTemplateAPI.MTemplateError.kTemplateErrorTypeWarning)
  170. return MTemplateAPI.MTemplateError()
  171. def onApplicationFinder(self, moduleRegExp, moduleTag):
  172. return MTemplateAPI.kTemplateScanNone
  173. def onFindApplication(self, basePath, clientTemplatePreferences):
  174. pass
  175. ''' Create an instance of the template class and install it into the template manager context '''
  176. template = ShellTemplate()
  177. manager.installPyTemplate(template)