Ejemplo n.º 1
0
    def add_recipe_folder(self, recipe_folder, whitelist=None):
        """Add all recipes inside a folder to this RecipeManager with an optional whitelist.

        Args:
            recipe_folder (str): The path to the folder of recipes to add.
            whitelist (list): Only include files whose os.basename() matches something
                on the whitelist
        """

        if whitelist is not None:
            whitelist = set(whitelist)

        if recipe_folder == '':
            recipe_folder = '.'

        for yaml_file in [
                x for x in os.listdir(recipe_folder) if x.endswith('.yaml')
        ]:
            if whitelist is not None and yaml_file not in whitelist:
                continue

            recipe = RecipeObject.FromFile(
                os.path.join(recipe_folder, yaml_file), self._recipe_actions,
                self._recipe_resources)
            self._recipes[recipe.name] = recipe

        for ship_file in [
                x for x in os.listdir(recipe_folder) if x.endswith('.ship')
        ]:
            if whitelist is not None and ship_file not in whitelist:
                continue

            recipe = RecipeObject.FromArchive(
                os.path.join(recipe_folder, ship_file), self._recipe_actions,
                self._recipe_resources)
            self._recipes[recipe.name] = recipe
Ejemplo n.º 2
0
    def get_recipe(self, recipe_name):
        """Get a recipe by name.

        Args:
            recipe_name (str): The name of the recipe to fetch. Can be either the
                yaml file name or the name of the recipe.
        """
        if recipe_name.endswith('.yaml'):
            recipe = self._recipes.get(
                RecipeObject.FromFile(recipe_name, self._recipe_actions,
                                      self._recipe_resources).name)
        else:
            recipe = self._recipes.get(recipe_name)
        if recipe is None:
            raise RecipeNotFoundError(
                "Could not find recipe",
                recipe_name=recipe_name,
                known_recipes=[x for x in self._recipes.keys()])

        return recipe