1
0
Fork 0
mirror of synced 2024-05-27 20:41:12 -04:00

Use file extension to select config file parser

This patch makes Dotbot provide better error messages when parsing JSON
files.
This commit is contained in:
Anish Athalye 2016-01-13 13:46:41 -05:00
parent c48d16cbce
commit 47ad7f4d3b

View file

@ -1,5 +1,6 @@
import yaml
import json
import os.path
from .util import string
class ConfigReader(object):
@ -8,17 +9,13 @@ class ConfigReader(object):
def _read(self, config_file_path):
try:
_, ext = os.path.splitext(config_file_path)
with open(config_file_path) as fin:
try:
print ext
if ext == '.json':
data = json.load(fin)
else:
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))