fix for fermenter_recipe_controller and flexible config path

This commit is contained in:
avollkopf 2022-04-01 19:28:17 +02:00
parent 46a589c463
commit fec02047ad
2 changed files with 10 additions and 6 deletions

View file

@ -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:

View file

@ -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