def __GetSingleImageTag(self, mainDir, filename, width, height, link = None): if (filename == None): return "Missing File" filename = FUtils.GetHtmlRelativePath(filename, mainDir) ext = FUtils.GetExtension(filename) if (link == None): link = filename else: link = FUtils.GetHtmlRelativePath(link, mainDir) tag = "<a href=\"" + link + "\"><img " if (FUtils.IsImageFile(ext)): tag = tag + "src=\"" + filename + "\" border=\"0\" " elif (ext == "dae"): tag = tag + "alt=\"Collada File\" border=\"1\" " elif (ext == "max"): tag = tag + "alt=\"Max File\" border=\"1\" " elif (ext == "mb"): tag = tag + "alt=\"Maya Binary File\" border=\"1\" " elif (ext == "ma"): tag = tag + "alt=\"Maya Ascii File\" border=\"1\" " else: tag = tag + "alt=\"Ext: " + ext + "\" border=\"1\" " return (tag + "" + "width=\"" + str(width) + "\" height=\"" + str(height) + "\"></a>")
def __GetOpenFunc(self, file, type, grid): # Should we open an external loader? internalLoad = (type == FImageType.ANIMATION) if (type == FImageType.IMAGE): extension = FUtils.GetExtension(file).lower() if (extension == "png"): internalLoad = True file = [file] if internalLoad: def Open(e): # Open the internal viewer as a separate process. args = ([ "\"" + self.__pythonPath + "\"", "\"" + FImageRenderer.__ANIMATION_FRAME_EXECUTABLE + "\"" ]) for filename in file: args.append("\"" + filename + "\"") os.spawnv(os.P_DETACH, self.__pythonPath, args) else: def Open(e): # Open the default viewer for this file. if (os.path.isfile(file)): # XXX: this is windows only os.startfile("\"" + file + "\"") else: FUtils.ShowWarning(grid.GetParent(), "Missing File.") return Open
def __GetImage(self, filename): if (not os.path.isfile(filename)): return wx.ImageFromBitmap( wx.ArtProvider.GetBitmap(wx.ART_MISSING_IMAGE, wx.ART_OTHER, (48, 48))) if (self.__IsRecognizable(filename)): return wx.Image(filename, wx.BITMAP_TYPE_ANY) bitmap = wx.EmptyBitmap(FImageData.__BITMAP_WIDTH, FImageData.__BITMAP_HEIGHT) dc = wx.MemoryDC() dc.SelectObject(bitmap) dc.SetBackground(wx.WHITE_BRUSH) dc.Clear() dc.SetPen(wx.BLACK_PEN) bitmapWidth = FImageData.__BITMAP_WIDTH - 2 bitmapHeight = FImageData.__BITMAP_HEIGHT - 2 dc.DrawRectangle(0, 0, bitmapWidth, bitmapHeight) dc.SetBackgroundMode(wx.TRANSPARENT) dc.SetTextBackground(wx.WHITE) dc.SetTextForeground(wx.BLACK) font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) font.SetWeight(wx.BOLD) dc.SetFont(font) ext = FUtils.GetExtension(filename) if (ext == "dae"): text = "Collada File" elif (ext == "max"): text = "Max File" elif (ext == "ma"): text = "Maya Ascii File" elif (ext == "mb"): text = "Maya Binary File" else: text = ext + " File" width1, height1 = dc.GetTextExtent(text) width2, height2 = dc.GetTextExtent("(No Preview)") width = max(width1, width2) height = height1 + height2 + FImageData.__HEIGHT_SPACING textY = (bitmapHeight - height) / 2 dc.DrawText(text, (bitmapWidth - width1) / 2, textY) dc.DrawText("(No Preview)", (bitmapWidth - width2) / 2, textY + height1 + FImageData.__HEIGHT_SPACING) return bitmap.ConvertToImage()
def __eq__(self, other): if other is None: return False if (self.__comments != other.__comments): return False if (self.__environment != other.__environment): return False if (self.__crashIndices != other.__crashIndices): return False if (self.__judgingResults != other.__judgingResults): return False if (self.__checksum != other.__checksum): return False # Do not compare judging logs. # Do not compare time ran. if (len(self.__errorCounts) != len(other.__errorCounts)): return False for i in range(len(self.__errorCounts)): if (self.__errorCounts[i] != other.__errorCounts[i]): return False if (len(self.__warningCounts) != len(other.__warningCounts)): return False for i in range(len(self.__warningCounts)): if (self.__warningCounts[i] != other.__warningCounts[i]): return False # Do not compare log locations. if (len(self.__outputLocations) != len(other.__outputLocations)): return False for i in range(len(self.__outputLocations)): # validation if ((type(self.__outputLocations[i]) is types.StringType) and (type(other.__outputLocations[i]) is types.StringType)): continue if ((self.__outputLocations[i] == None) and (other.__outputLocations[i] == None)): continue if ((self.__outputLocations[i] == None) or (other.__outputLocations[i] == None)): return False if (len(self.__outputLocations[i]) != len( other.__outputLocations[i])): return False for j in range(len(self.__outputLocations[i])): #todo what happens if file not there ext = FUtils.GetExtension(self.__outputLocations[i][j]) if (FUtils.IsImageFile(ext)): compareResult = FGlobals.imageComparator.CompareImages( self.__outputLocations[i][j], other.__outputLocations[i][j]) if (not compareResult.GetResult()): return False return True
def WriteImport(self, filename, logname, outputDir, settings, isAnimated, cameraRig, lightingRig): """WriteImport(filename, logname, outputDir, settings, isAnimated, cameraRig, lightingRig) -> list_of_str Implements FApplication.WriteImport() """ self.__testCount = self.__testCount + 1 baseName = FUtils.GetProperFilename(filename) self.__currentImportProperName = baseName baseName = baseName + FMax.__EXTENSION output = (os.path.join(outputDir, baseName)).replace("\\", "\\\\") writeableDir = os.path.dirname(filename).replace("\\", "\\\\") writeableFilename = filename.replace("\\", "\\\\") if (FUtils.GetExtension(filename) == FMax.__EXTENSION[1:]): command = " loadMaxFile my_importfilename useFileUnits:true quiet:true\n" else: command = " importFile my_importfilename #noprompt using:OpenCOLLADAImporter\n" cfgFilename = os.path.normpath( self.configDict["maxColladaExporterFilename"]) cfgFilename = cfgFilename.replace("\\", "\\\\") options = "".join([ " setINISetting \"%s\" \"ColladaMax\" \"%s\" \"%s\"\n" % (cfgFilename, setting.GetCommand(), setting.GetValue()) for setting in settings ]) self.__script.write( "logfilename = \"" + logname.replace("\\", "\\\\") + "\"\n" + "openLog logfilename mode:\"w\" outputOnly:true\n" + "try (\n" + " resetmaxfile #noprompt\n" + options + " sysInfo.currentdir = \"" + writeableDir + "\"\n" + " my_importfilename = \"" + writeableFilename + "\"\n" + command + " saveMaxFile \"" + output + "\"\n" + " print \"Import succeeded with " + writeableFilename + "\"\n" + ") catch (\n" + " print \"Import error with " + writeableFilename + "\"\n" + ")\n" + "flushLog()\n" + "closeLog()\n\n") return [ os.path.normpath(baseName), ]
def WriteImport(self, filename, logname, outputDir, settings, isAnimated, cameraRig, lightingRig): """WriteImport(filename, logname, outputDir, settings, isAnimated, cameraRig, lightingRig) -> list_of_str Implements FApplication.WriteImport(). Assumes a COLLADA, maya binary, or maya ascii file is being imported. """ baseName = FUtils.GetProperFilename(filename) self.__currentImportProperName = baseName output = (os.path.join(outputDir, baseName)).replace("\\", "/") filename = filename.replace("\\", "/") self.__currentFilename = output + ".mb" # Generate the import options string. options = "" for setting in settings: value = setting.GetValue().strip() if len(value) == 0: value = self.FindDefault(FMaya_UIRender.__IMPORT_OPTIONS, setting.GetPrettyName()) options = (options + setting.GetCommand() + "=" + value + ";") # Generate the import MEL command. extension = FUtils.GetExtension(filename).lower() if (extension == "mb"): command = ("catch(`file -type \"mayaBinary\" -o \"" + filename + "\"`);\n") elif (extension == "ma"): command = ("catch(`file -type \"mayaAscii\" -o \"" + filename + "\"`);\n") else: command = ("catch(`file -type \"COLLADA importer\" -op \"" + options + "\" -o \"" + filename + "\"`);\n") self.__melScript.write( "$logname = \"" + logname.replace("\\", "/") + "\";\n" + "$descriptor = `cmdFileOutput -o $logname`;\n" + "catch(`file -f -new`);\n" + command + "catch(`file -rename \"" + output + "\"`);\n" + "catch(`file -save -type \"mayaBinary\"`);\n" + "cmdFileOutput -c $descriptor;\n" + "fixNewlines $logname;\n\n") self.__testImportCount = self.__testImportCount + 1 return [os.path.normpath(baseName + ".mb"),]
def Validate(self, filename, testProcedure, testId): # Execute the validation steps. for step in self.__validationList: if (step != 0): lastOutputs = self.GetOutputLocation(step - 1) if (lastOutputs != None): # only validates the last one documentFilename = lastOutputs[-1] else: documentFilename = None if (documentFilename != None): documentFilename = os.path.abspath(documentFilename) stepName = STEP_PREFIX + str(step) outDir = os.path.abspath( os.path.join(self.__executionDir, stepName)) logFilename = stepName + "." + LOG_EXT logAbsFilename = os.path.join(outDir, logFilename) try: os.mkdir(outDir) except OSError, e: print "<FExecution> could not make the step directory" print e if ((documentFilename != None) and (FUtils.GetExtension(documentFilename).lower() == "dae")): os.system("SchemaValidate.exe \"" + documentFilename + "\" \"" + SCHEMA_LOCATION + "\" \"" + SCHEMA_NAMESPACE + "\" \"" + logAbsFilename + "\"") else: logFile = open(logAbsFilename, "w") logFile.write("Error: Not a Collada file.\n") logFile.close() self.__outputFilenames[step] = logFilename self.__outputLocations[step] = logAbsFilename errors, warnings = self.__ParseValidation(logAbsFilename) self.__errorCounts[step] = errors self.__warningCounts[step] = warnings
def RunScript(self): """RunScript() -> None Implements FApplication.RunScript() """ if (not os.path.isfile(self.configDict["mayaPath"])): print "Maya does not exist" return True command = ("\"" + self.configDict["mayaPath"] + "\" -batch -script \"" + self.__melScript.name + "\"") # quotes around command is awkward, but seems like the only way works print ("start running " + os.path.basename(self.__melScript.name)) returnValueImport = self.RunApplication(command, self.__workingDir) if (returnValueImport == 0): print "finished running " + os.path.basename(self.__melScript.name) else: print "crashed running " + os.path.basename(self.__melScript.name) # Maya has a tendency to dump images where I don't want them to be. # Look for images in the sub-folders of the output folder and move them to the output folder. for renderFolder in self.__renderFolders: subFolders = [renderFolder] while (len(subFolders) > 0): subFolder = subFolders[-1] subFolders.pop() for dirEntry in os.listdir(subFolder): pathname = os.path.join(subFolder, dirEntry) mode = os.stat(pathname)[ST_MODE] if S_ISDIR(mode): # Add this sub-folder to our queue. subFolders.append(pathname) elif S_ISREG(mode): # Process all python script files, except for the __init__.py ones. if FUtils.GetExtension(pathname).lower() == "png": shutil.move(pathname, os.path.join(renderFolder, dirEntry)) self.__renderFolders = [] return (returnValueImport == 0)
def __init__(self): FSerializer.__init__(self) # Read in and parse the configuration file. configDict = {} if (os.path.isfile(CONFIGURATION_FILE)): f = open(CONFIGURATION_FILE) line = f.readline() while (line): while (line.count("\t\t") > 0): line = line.replace("\t\t", "\t") key, value = line.split("\t", 1) if (configDict.has_key(key)): print("Warning: Ignoring redefinition of configuration " + "key: " + key + ".") continue configDict[key] = value.strip() # remove \n line = f.readline() f.close # Further parse the badge levels configuration. FGlobals.badgeLevels = [] if configDict.has_key("badgeLevels"): wantedBadgeList = configDict["badgeLevels"].split(",") for badge in wantedBadgeList: # Strip extra whitespaces and enforce title-case. level = badge.strip().title() if (len(level) > 0): FGlobals.badgeLevels.append(level) # Further parse the adopter package status FGlobals.adoptersPackage = False if configDict.has_key("adoptersPackage"): FGlobals.adoptersPackage = configDict["adoptersPackage"] print "IsAdopters %s" % (FGlobals.adoptersPackage) # import the application specific scripts self.applicationMap = {} if (os.path.isdir(SCRIPTS_DIR)): for entry in os.listdir(SCRIPTS_DIR): filename = os.path.normpath(os.path.join(SCRIPTS_DIR, entry)) if ((not os.path.isfile(filename)) or (FUtils.GetExtension(filename) != "py") or (entry == "__init__.py") or (entry == ABSTRACT_APPLICATION)): continue properName = FUtils.GetProperFilename(entry) exec("from Scripts." + properName + " import *") exec("application = " + properName + "(configDict)") prettyName = application.GetPrettyName() if (self.applicationMap.has_key(prettyName)): print("Warning: Ignoring redefinition of application \"" + prettyName + "\" from \"" + entry + "\"") continue self.applicationMap[prettyName] = application # import the image comparator comparatorFile = os.path.abspath( os.path.normpath( os.path.join(IMAGE_COMPARATORS_DIR, configDict[IMAGE_COMPARATORS_LABEL] + ".py"))) if (os.path.isfile(comparatorFile)): comparatorName = configDict[IMAGE_COMPARATORS_LABEL] else: print comparatorFile + " not found. Defaulting to byte comparator." comparatorName = "FByteComparator" # default comparator exec("from ImageComparators." + comparatorName + " import *") exec("FGlobals.imageComparator = " + comparatorName + "(configDict)") self.configDict = configDict
def WriteImport(self, filename, logname, outputDir, settings, isAnimated, cameraRig, lightingRig): """WriteImport(filename, logname, outputDir, settings, isAnimated, cameraRig, lightingRig) -> list_of_str Implements FApplication.WriteImport() """ step = os.path.basename(outputDir) execution = os.path.basename(os.path.dirname(outputDir)) test = os.path.basename(os.path.dirname(os.path.dirname(outputDir))) path = os.path.join(self.__scenesDir, test, execution, step) if (not os.path.isdir(path)): os.makedirs(path) self.__pathMap.append((path, outputDir)) self.__logFiles.append(os.path.join(path, os.path.basename(logname))) self.__importLogFiles.append(self.__logFiles[-1]) command = ("SetValue \"preferences.scripting.cmdlogfilename\", \"" + self.__logFiles[-1].replace("\\", "\\\\") + "\"\n" "NewScene, false\n") if (FUtils.GetExtension(filename) == "dae"): command = (command + "set myIProp = CreateImportFTKOptions()\n" + "myIProp.Parameters(\"Filename\").Value = \"" + filename.replace("\\", "\\\\") + "\"\n" + "myIProp.Parameters(\"Verbose\").Value = True\n") for setting in settings: value = setting.GetValue().strip() if (value == ""): value = self.FindDefault(FXsi.__IMPORT_OPTIONS, setting.GetPrettyName()) command = (command + "myIProp.Parameters(\"" + setting.GetCommand() + "\").Value = " + value + "\n") command = command + "ImportFTK myIProp.Name \n" elif (FUtils.GetExtension(filename) == "scn"): command = (command + "OpenScene \"" + filename.replace("\\", "\\\\") + "\"\n") else: return self.__currentImportProperName = FUtils.GetProperFilename(filename) basename = self.__currentImportProperName + ".scn" # self.__script.write( # command + # "SearchAndReplacePath \"All\", \"" + FXsi.__REPLACE_PATH + # "\", \"" + # os.path.dirname(filename).replace("\\", "\\\\") + # "\", True\n" + # "SaveSceneAs \"" + # os.path.join(path, basename).replace("\\", "\\\\") + # "\"\n" # ) self.__script.write( command + "SaveSceneAs \"" + os.path.join(path, basename).replace("\\", "\\\\") + "\"\n") self.__testCount = self.__testCount + 1 return [ basename, ]
def __IsRecognizable(self, filename): extension = FUtils.GetExtension(filename) return FUtils.IsImageFile(extension)