def _LoadRecipe(self, recipeID):
        recipeRow = cfg.recipes.GetIfExists(recipeID)
        if recipeRow is None:
            return {}
        if recipeRow.parentRecipeID:
            recipe = self.GetRecipe(recipeRow.parentRecipeID)
        else:
            recipe = {}
        ingredients = cfg.entityIngredientsByRecipeID.get(recipeID, [])
        for row in ingredients:
            if row.componentID not in recipe:
                recipe[row.componentID] = BaseComponentView.GetDefaultRecipe(
                    row.componentID)
            self._LoadInitValues(recipe[row.componentID], row.ingredientID)

        spawn = cfg.entitySpawnsByRecipeID.get(recipeID, None)
        if spawn:
            spawn = spawn[0]
            recipeWithDefaults = {}
            for componentID, componentRecipe in recipe.iteritems():
                componentRecipe['_spawnID'] = spawn.spawnID
                defaultsDict = BaseComponentView.GetDefaultRecipe(
                    componentID, groupFilter=cef.BaseComponentView.ALL_STATIC)
                recipeWithDefaults[componentID] = defaultsDict

            self._IntegrateDicts(recipeWithDefaults, recipe)
            recipe = recipeWithDefaults
        for componentState in recipe.itervalues():
            componentState['_recipeID'] = recipeID

        self.recipes[recipeID] = recipe
        return recipe
Esempio n. 2
0
    def _ValidateEachComponent(self, result, recipeID, recipeDict):
        perComponentValidationFuncs = [
            self._ValidateComponentViewIsDefined,
            self._ValidateComponentSpawnInputs,
            self._ValidateComponentDependencies,
            self._ValidateCustomComponentInfo
        ]
        for componentID in recipeDict:
            componentView = BaseComponentView.GetComponentViewByID(componentID)
            componentResult = ValidationMessage(
                name=self._GetComponentName(componentView, componentID))
            for validationFunc in perComponentValidationFuncs:
                try:
                    canContinue = validationFunc(componentResult, recipeID,
                                                 recipeDict, componentView,
                                                 componentID)
                except Exception as e:
                    self.LogError(
                        'An error occurred while running validation for component "%s" at recipeID=%s'
                        % (componentView.__COMPONENT_DISPLAY_NAME__, recipeID))
                    log.LogException(e)
                    componentResult.AddMessage(
                        'An error occurred while running validation for this component'
                    )
                    canContinue = True

                if not canContinue:
                    break

            result.AddMessage(componentResult)
Esempio n. 3
0
def GetComponentName(componentID):
    componentView = BaseComponentView.GetComponentViewByID(componentID)
    if type(componentID) is str:
        return componentID
    if componentView is None:
        log.LogTraceback('UNKNOWN COMPONENT %s' % componentID)
        return 'UNKNOWN COMPONENT %s' % componentID
    return componentView.__COMPONENT_CODE_NAME__
Esempio n. 4
0
def ShouldSpawnOn(componentIDList, spawnLoc):
    shouldSpawn = False
    for componentID in componentIDList:
        componentView = BaseComponentView.GetComponentViewByID(componentID)
        spawnHere = componentView.__SHOULD_SPAWN__.get(spawnLoc, None)
        if spawnHere is False:
            return False
        if spawnHere:
            shouldSpawn = True

    return shouldSpawn
def GetComponentName(componentID):
    """
    Important Distinction:
      This gets the CODE name of the component, that is used as a real code variable name.
    It's QUITE urgent that those code names are never changed once defined,
      due to a bunch of weird things the components do, and how they're used.
    """
    componentView = BaseComponentView.GetComponentViewByID(componentID)
    if type(componentID) is str:
        return componentID
    if componentView is None:
        log.LogTraceback('UNKNOWN COMPONENT %s' % componentID)
        return 'UNKNOWN COMPONENT %s' % componentID
    return componentView.__COMPONENT_CODE_NAME__
def ShouldSpawnOn(componentIDList, spawnLoc):
    """
    Takes in a list of componentID's and based on this determines if for the
    boot role specified if these components would be spawned on this role.
    """
    shouldSpawn = False
    for componentID in componentIDList:
        componentView = BaseComponentView.GetComponentViewByID(componentID)
        spawnHere = componentView.__SHOULD_SPAWN__.get(spawnLoc, None)
        if spawnHere is False:
            return False
        if spawnHere:
            shouldSpawn = True

    return shouldSpawn
Esempio n. 7
0
    def _ValidateComponentDependencies(self, result, recipeID, recipeDict,
                                       componentView, componentID):
        dependentComponentIDs = componentView.GetDependencies()
        for otherComponentID in dependentComponentIDs:
            otherComponentView = BaseComponentView.GetComponentViewByID(
                otherComponentID)
            if otherComponentView is None:
                result.AddMessage(
                    'Contact Programmer: Invalid dependent component: %s' %
                    otherComponentID)
                continue
            if otherComponentID not in recipeDict:
                result.AddMessage(
                    'Missing component: %s' %
                    otherComponentView.__COMPONENT_DISPLAY_NAME__)

        return True