Skip to content

Commit

Permalink
Add config loader for json and yaml.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdragon-001 committed May 29, 2020
1 parent 7622739 commit 41a6a2d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions runrestic/runrestic/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import jsonschema
import pkg_resources
import toml

from runrestic import __version__
from runrestic.runrestic.tools import deep_update
Expand Down Expand Up @@ -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(
Expand All @@ -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))

Expand Down

0 comments on commit 41a6a2d

Please sign in to comment.