From 1926c1d6457177e001d137f4f929f35e4d73c3cf Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Mon, 3 Jul 2023 07:22:15 +0300 Subject: [PATCH] Refactor update_yaml_file function to separate the logic for updating YAML data into a new function update_yaml(). --- frigate/util.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frigate/util.py b/frigate/util.py index 9bb816732..c1f1fee61 100755 --- a/frigate/util.py +++ b/frigate/util.py @@ -1235,6 +1235,13 @@ def update_yaml_file(file_path, key_path, new_value): with open(file_path, "r") as f: data = yaml.load(f) + data = update_yaml(data, key_path, new_value) + + with open(file_path, "w") as f: + yaml.dump(data, f) + + +def update_yaml(data, key_path, new_value): temp = data for key in key_path[:-1]: if isinstance(key, tuple): @@ -1271,5 +1278,4 @@ def update_yaml_file(file_path, key_path, new_value): else: temp[last_key] = new_value - with open(file_path, "w") as f: - yaml.dump(data, f) + return data