1
0
Fork 0
mirror of synced 2024-06-14 05:11:09 -04:00
dotbot/dotbot/config.py
Anish Athalye c48d16cbce Use standard library JSON parser for JSON files
This patch reverts the changes to the README made in
57265f78b4 and makes it so that Dotbot
supports JSON files with tab characters.
2016-01-13 11:29:12 -05:00

32 lines
944 B
Python

import yaml
import json
from .util import string
class ConfigReader(object):
def __init__(self, config_file_path):
self._config = self._read(config_file_path)
def _read(self, config_file_path):
try:
with open(config_file_path) as fin:
try:
data = yaml.safe_load(fin)
except Exception as e:
# try falling back to JSON, but return original exception
# if that fails too
try:
fin.seek(0)
data = json.load(fin)
except Exception:
raise e
return data
except Exception as e:
msg = string.indent_lines(str(e))
raise ReadingError('Could not read config file:\n%s' % msg)
def get_config(self):
return self._config
class ReadingError(Exception):
pass