From 9005685ab5a8a780102ed3899467aa0456a07714 Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Sun, 11 Jun 2023 22:11:16 +0200 Subject: [PATCH] change creations conditions format --- src/utils/creation_utils.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/utils/creation_utils.py b/src/utils/creation_utils.py index fc5021c..d5a747a 100644 --- a/src/utils/creation_utils.py +++ b/src/utils/creation_utils.py @@ -19,15 +19,12 @@ def are_all_conditions_met(lxc): result = [] - for condition in conditions: - if condition["type"] == "file": - result.append(Path(condition["path"]).is_file()) - elif condition["type"] == "folder": - result.append(Path(condition["path"]).is_dir()) - elif condition["type"] == "program": - result.append(lxc.run_command("which " + condition["program"], only_code=True) == 0) - else: - raise Exception(f"Unknown condition type {condition['type']}") + for file in conditions['files']: + result.append(Path(file).is_file()) + for folder in conditions['folders']: + result.append(Path(folder).is_dir()) + for program in conditions['programs']: + result.append(lxc.run_command("which " + program, only_code=True) == 0) if all(result): logging.info(f"All creations conditions met for LXC {lxc.lxc_id}, running deploy steps...") @@ -44,14 +41,11 @@ def run_creations_steps(lxc): :param lxc: lxc :return: None """ - creation = lxc.get_creation() creation_steps = creation["creation_steps"] for step in creation_steps: - if step["type"] == "command": - lxc.run_command(step["command"]) - elif step["type"] == "script": - lxc.run_script(step["script"]) - else: - raise Exception(f"Unknown creation step type {step['type']}") + match step["type"]: + case "file": + if type(step["path"]) is list: + pass