From f96ab104e8f83ef1aad52cf152cb2d92939519c0 Mon Sep 17 00:00:00 2001 From: saltydk Date: Wed, 25 Oct 2023 08:06:07 +0200 Subject: [PATCH] settings: update settings-updater.py --- roles/settings/files/settings-updater.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/roles/settings/files/settings-updater.py b/roles/settings/files/settings-updater.py index 00bb54e8cc..c9a575a6ee 100644 --- a/roles/settings/files/settings-updater.py +++ b/roles/settings/files/settings-updater.py @@ -3,7 +3,7 @@ ######################################################################### # Title: Settings Updater Script # - # Author(s): l3uddz # + # Author(s): l3uddz, salty # # URL: https://github.com/saltyorg/Sandbox # # Description: Adds variables to settings.yml. # # -- # @@ -17,7 +17,7 @@ import sys from logging.handlers import RotatingFileHandler -from ruamel import yaml +from ruamel.yaml import YAML from ruamel.yaml.comments import CommentedMap ############################################################ @@ -65,9 +65,13 @@ def init_logging(playbook_path): ############################################################ def load_settings(file_to_load): + yaml_instance = YAML() + yaml_instance.preserve_quotes = True + settings = None try: - settings = yaml.round_trip_load(open(file_to_load, "r"), preserve_quotes=True) + with open(file_to_load, "r") as f: + settings = yaml_instance.load(f) except Exception: log.exception("Exception loading %s: ", file_to_load) return settings @@ -76,9 +80,10 @@ def load_settings(file_to_load): def dump_settings(settings, file_to_dump): dumped = False try: + yaml_instance = YAML() + yaml_instance.preserve_quotes = True with open(file_to_dump, 'w') as fp: - yaml.round_trip_dump(settings, fp, indent=2, block_seq_indent=2, - explicit_start=True, default_flow_style=False) + yaml_instance.dump(settings, fp) dumped = True except Exception: log.exception("Exception dumping upgraded %s: ", file_to_dump)