mirror of
1
0
Fork 0
dotbot/dotbot/config.py

32 lines
755 B
Python
Raw Normal View History

import json
import os.path
import yaml
from .util import string
2014-03-19 23:07:30 -04:00
2022-01-30 18:48:30 -05:00
class ConfigReader:
2014-03-19 23:07:30 -04:00
def __init__(self, config_file_path):
self._config = self._read(config_file_path)
def _read(self, config_file_path):
try:
_, ext = os.path.splitext(config_file_path)
2014-03-19 23:07:30 -04:00
with open(config_file_path) as fin:
2022-01-30 18:48:30 -05:00
if ext == ".json":
data = json.load(fin)
else:
data = yaml.safe_load(fin)
2014-03-19 23:07:30 -04:00
return data
except Exception as e:
msg = string.indent_lines(str(e))
2022-01-30 18:48:30 -05:00
raise ReadingError("Could not read config file:\n%s" % msg)
2014-03-19 23:07:30 -04:00
def get_config(self):
return self._config
2022-01-30 18:48:30 -05:00
2014-03-19 23:07:30 -04:00
class ReadingError(Exception):
pass