Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config loader for json and yaml #37

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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