From fec02047adad26ed41f058ac60e04f9a17d4e58a Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 1 Apr 2022 19:28:17 +0200 Subject: [PATCH] fix for fermenter_recipe_controller and flexible config path --- cbpi/configFolder.py | 7 +++++-- cbpi/controller/fermenter_recipe_controller.py | 9 +++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cbpi/configFolder.py b/cbpi/configFolder.py index 8485442..542ce73 100644 --- a/cbpi/configFolder.py +++ b/cbpi/configFolder.py @@ -1,4 +1,6 @@ import os +from os import listdir +from os.path import isfile, join import pathlib import platform import shutil @@ -26,8 +28,9 @@ class ConfigFolder: return os.path.join(self._rawPath, 'fermenterrecipes', "{}.yaml".format(recipe_id)) def get_all_fermenter_recipes(self): - fermenter_recipes_folder = os.path.join(self._rawPath, 'fermenterrecipes', '*.yaml') - return glob.glob(fermenter_recipes_folder) + fermenter_recipes_folder = os.path.join(self._rawPath, 'fermenterrecipes') + fermenter_recipe_ids = [os.path.splitext(f)[0] for f in listdir(fermenter_recipes_folder) if isfile(join(fermenter_recipes_folder, f)) and f.endswith(".yaml")] + return fermenter_recipe_ids def check_for_setup(self): if self.config_file_exists("config.yaml") is False: diff --git a/cbpi/controller/fermenter_recipe_controller.py b/cbpi/controller/fermenter_recipe_controller.py index fe1f7fb..0ab6aa5 100644 --- a/cbpi/controller/fermenter_recipe_controller.py +++ b/cbpi/controller/fermenter_recipe_controller.py @@ -43,14 +43,15 @@ class FermenterRecipeController: async def get_recipes(self): - fermenter_recipes = self.cbpi.config_folder.get_all_fermenter_recipes() + fermenter_recipe_ids = self.cbpi.config_folder.get_all_fermenter_recipes() result = [] - for filename in fermenter_recipes: - with open(filename) as file: + for recipe_id in fermenter_recipe_ids: + + with open(self.cbpi.config_folder.get_fermenter_recipe_by_id(recipe_id)) as file: data = yaml.load(file, Loader=yaml.FullLoader) dataset = data["basic"] - dataset["file"] = filename + dataset["file"] = recipe_id result.append(dataset) logging.info(result) return result