From 41a6a2d4c9b19e31056ba59e6bd3cdbe4c5b7a36 Mon Sep 17 00:00:00 2001 From: Dark Dragon Date: Fri, 29 May 2020 21:12:06 +0200 Subject: [PATCH] Add config loader for json and yaml. --- runrestic/runrestic/configuration.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/runrestic/runrestic/configuration.py b/runrestic/runrestic/configuration.py index d0f3288..dfaff12 100644 --- a/runrestic/runrestic/configuration.py +++ b/runrestic/runrestic/configuration.py @@ -6,7 +6,6 @@ import jsonschema import pkg_resources -import toml from runrestic import __version__ from runrestic.runrestic.tools import deep_update @@ -102,7 +101,7 @@ def configuration_file_paths() -> Sequence[str]: for filename in os.listdir(path): filename = os.path.join(path, filename) - if filename.endswith(".toml") and not os.path.isdir(filename): + if filename.endswith(('.json','.yaml','.yml','.toml')) and not os.path.isdir(filename): octal_permissions = oct(os.stat(filename).st_mode) if octal_permissions[-2:] != "00": # file permissions are too broad logger.warning( @@ -122,7 +121,15 @@ def configuration_file_paths() -> Sequence[str]: def parse_configuration(config_filename: str) -> Dict[str, Any]: logger.debug(f"Parsing configuration file: {config_filename}") with open(config_filename) as file: - config = toml.load(file) + if config_filename.endswith('.json'): + import json + config = json.load(file) + if config_filename.endswith(('.yaml','.yml')): + import yaml + config = yaml.load(file) + if config_filename.endswith('.toml'): + import toml + config = toml.load(file) config = deep_update(CONFIG_DEFAULTS, dict(config))