Exemplo n.º 1
0
    def LoadRecipe(self, recipe):
        """Populates the internal module pool with modules declared in a recipe.

    Args:
      recipe (dict[str, str]): recipe declaring modules to load.

    Raises:
      RecipeParseError: if a module in the recipe does not exist.
    """
        self.recipe = recipe
        module_definitions = recipe.get('modules', [])
        preflight_definitions = recipe.get('preflights', [])
        for module_definition in module_definitions + preflight_definitions:
            # Combine CLI args with args from the recipe description
            module_name = module_definition['name']
            module_class = modules_manager.ModulesManager.GetModuleByName(
                module_name)
            if not module_class:
                raise errors.RecipeParseError(
                    'Recipe uses unknown module: {0:s}'.format(module_name))

            runtime_name = module_definition.get('runtime_name')
            if not runtime_name:
                runtime_name = module_name
            self._module_pool[runtime_name] = module_class(self,
                                                           name=runtime_name)
Exemplo n.º 2
0
  def ReadRecipeFromFile(self, path):
    """Reads a recipe from a JSON file.

    Args:
      path (str): path of the recipe JSON file.

    Raises:
      RecipeParseError: when the recipe cannot be parsed.
    """
    with io.open(path, 'r', encoding='utf-8') as file_object:
      try:
        recipe = self._ReadRecipeFromFileObject(file_object)
      except json.decoder.JSONDecodeError as exception:
        raise errors.RecipeParseError(
            'Unable to parse recipe file: {0:s} with error: {1!s}'.format(
                path, exception))

    self.RegisterRecipe(recipe)
Exemplo n.º 3
0
    def LoadRecipe(self, recipe):
        """Populates the internal module pool with modules declared in a recipe.

    Args:
      recipe (dict[str, str]): recipe declaring modules to load.

    Raises:
      RecipeParseError: if a module in the recipe does not exist.
    """
        self.recipe = recipe
        for module_description in recipe['modules']:
            # Combine CLI args with args from the recipe description
            module_name = module_description['name']
            module_class = modules_manager.ModulesManager.GetModuleByName(
                module_name)
            if not module_class:
                raise errors.RecipeParseError(
                    'Recipe uses unknown module: {0:s}'.format(module_name))

            self._module_pool[module_name] = module_class(self)