summaryrefslogtreecommitdiff
path: root/dotbot
diff options
context:
space:
mode:
authorAnish Athalye <me@anishathalye.com>2016-01-13 13:46:41 -0500
committerAnish Athalye <me@anishathalye.com>2016-01-13 13:46:41 -0500
commit47ad7f4d3b69315e25ae96099fe73b4d9cd7666e (patch)
treed69ff2bace0cb6e2edcfc89255bbe0ad09d6d4bc /dotbot
parentc48d16cbce1dc082bc0b2f8ab3f34e7c0829cf89 (diff)
Use file extension to select config file parser
This patch makes Dotbot provide better error messages when parsing JSON files.
Diffstat (limited to 'dotbot')
-rw-r--r--dotbot/config.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/dotbot/config.py b/dotbot/config.py
index a9aafa0..39ab60b 100644
--- a/dotbot/config.py
+++ b/dotbot/config.py
@@ -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))