Skip to content

Commit

Permalink
settings: update settings-updater.py
Browse files Browse the repository at this point in the history
  • Loading branch information
saltydk committed Oct 25, 2023
1 parent be01980 commit f96ab10
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions roles/settings/files/settings-updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. #
# -- #
Expand All @@ -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

############################################################
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f96ab10

Please sign in to comment.