From a4335ce8ac214994c9a01bf84a9e9753040c5019 Mon Sep 17 00:00:00 2001 From: Daan Selen Date: Tue, 25 Feb 2025 10:39:07 +0100 Subject: [PATCH] Expanded logic in replace_placeholder() function so this is easier to work with. --- meshbook.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/meshbook.py b/meshbook.py index f22e536..c878baa 100644 --- a/meshbook.py +++ b/meshbook.py @@ -102,7 +102,14 @@ async def replace_placeholders(meshbook: dict) -> dict: Replace the placeholders in both name and command fields of the tasks. According to the variables defined in the variables list. ''' - variables = {var["name"]: var["value"] for var in meshbook.get("variables", [])} + variables = {} + if "variables" in meshbook and isinstance(meshbook["variables"], list): + for var in meshbook["variables"]: + var_name = var["name"] + var_value = var["value"] + variables[var_name] = var_value + else: + return meshbook for task in meshbook.get("tasks", []): task_name = task.get("name")