示例#1
0
    def Run(self, appPython, step, op, inStep, filename, settings, isAnimated,
            cameraRig, lightingRig, markerCallBack):
        # First run: calculate the check-sum.
        if (len(self.__checksum) == 0):
            self.__checksum = FUtils.CalculateChecksum(filename)

        # Run the test steps.
        if (self.__initializedSteps.count(step) == 0):
            self.__InitializeRun(appPython, step, op, inStep, filename,
                                 settings, isAnimated, cameraRig, lightingRig,
                                 markerCallBack)
            self.__initializedSteps.append(step)
        else:
            stepName = STEP_PREFIX + str(step)
            outDir = os.path.abspath(
                os.path.join(self.__executionDir, stepName))
            logFilename = stepName + "." + LOG_EXT
            logAbsFilename = os.path.join(outDir, stepName + "." + LOG_EXT)

            if ((inStep == 0) or (self.__outputLocations[inStep] == None)):
                curInputFile = os.path.abspath(filename)
            else:
                curInputFile = os.path.abspath(
                    self.__outputLocations[inStep][-1])

            output = appPython.AddToScript(op, curInputFile, logAbsFilename,
                                           outDir, settings, isAnimated,
                                           cameraRig, lightingRig)

            if markerCallBack != None and len(output) > 0:
                # Some annoying scripts don't give us valid paths.
                if not os.path.isabs(output[0]):
                    markerCallBack(False, os.path.join(outDir, output[0]))
                else:
                    markerCallBack(False, output[0])
示例#2
0
    def Judge(self, filename, testProcedure, testId):
        # Look for a judging script
        scriptFilename = FUtils.ChangeExtension(filename, "py")
        try:
            # Set-up the judging script context.
            context = FJudgementContext(testProcedure, testId)

            if (os.path.exists(scriptFilename)):

                # Parse, compile and execute the judging script.
                judgingDictionary = {
                    'testProducedure': testProcedure,
                    'judgingObject': None
                }
                execfile(scriptFilename, judgingDictionary, judgingDictionary)
                if (judgingDictionary.has_key('judgingObject')):
                    judgingObject = judgingDictionary['judgingObject']

                    # We have a juding object.
                    # Look for and process all the wanted badge levels.
                    for i in range(len(FGlobals.badgeLevels)):
                        badgeLevel = FGlobals.badgeLevels[i]
                        judgingLevel = "Judge" + badgeLevel
                        if (judgingObject.__class__.__dict__.has_key(
                                judgingLevel)):
                            judgingFunction = judgingObject.__class__.__dict__[
                                judgingLevel]
                            if (callable(judgingFunction)):

                                # Run this judging function.
                                judgement = judgingFunction(
                                    judgingObject, context)

                                # Process the judgement
                                if judgement:
                                    self.__judgingResults[
                                        badgeLevel] = FJudgement.PASSED
                                else:
                                    self.__judgingResults[
                                        badgeLevel] = FJudgement.FAILED
                                judgingLog = context.GetLog()
                                if len(judgingLog) > 0:
                                    self.__judgingLogs[badgeLevel] = judgingLog
                                elif judgement:
                                    self.__judgingLogs[
                                        badgeLevel] = "Judgement passed."
                                else:
                                    self.__judgingLogs[
                                        badgeLevel] = "Judgement failed."
                                context.ResetLog()

                            else:
                                self.__judgingResults[
                                    badgeLevel] = FJudgement.MISSING_DATA
                                self.__judgingLogs[
                                    badgeLevel] = "Invalid judging script. '" + judgingLevel + "' is not a function."
                        else:
                            self.__judgingResults[
                                badgeLevel] = FJudgement.NO_SCRIPT
                            self.__judgingLogs[
                                badgeLevel] = "Judging script does not include the '" + badgeLevel + "' badge."

                    # We need that checksum too!
                    self.__checksum += "\n" + FUtils.CalculateChecksum(
                        scriptFilename)

                else:
                    for i in range(len(FGlobals.badgeLevels)):
                        badgeLevel = FGlobals.badgeLevels[i]
                        self.__judgingResults[
                            badgeLevel] = FJudgement.MISSING_DATA
                        self.__judgingLogs[
                            badgeLevel] = "Invalid judging script. Did not create the judging object."
            else:
                for i in range(len(FGlobals.badgeLevels)):
                    badgeLevel = FGlobals.badgeLevels[i]
                    self.__judgingResults[badgeLevel] = FJudgement.NO_SCRIPT
                    self.__judgingLogs[
                        badgeLevel] = "No judging script provided."

        except Exception, info:
            print "------------------------------------------------------------"
            print "<FExecution> could not run judging script: '" + os.path.basename(
                scriptFilename) + "'."
            print 'Exception is thrown at line %d in FExecution.py' % sys.exc_traceback.tb_lineno
            print info[0]
            print 'Trace back stack is:\n'
            traceback.print_exc()