1
0
Fork 0
mirror of synced 2024-05-27 20:41:12 -04:00
dotbot/dotbot/config.py

28 lines
759 B
Python
Raw Normal View History

import yaml
import json
import os.path
from .util import string
2014-03-19 23:07:30 -04:00
class ConfigReader(object):
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:
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))
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
class ReadingError(Exception):
pass