full json
[rainbowstream.git] / rainbowstream / config.py
1 import json
2 import os
3 import os.path
4
5 # Regular expression for comments
6 comment_re = re.compile(
7 '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
8 re.DOTALL | re.MULTILINE
9 )
10
11 def load_config(filepath):
12 try:
13 with open(filepath) as f:
14 content = ''.join(f.readlines())
15 match = comment_re.search(content)
16 while match:
17 content = content[:match.start()] + content[match.end():]
18 match = comment_re.search(content)
19 data = json.loads(content)
20 for d in data:
21 globals()[d] = data[d]
22 except:
23 pass
24
25 # Load colorset
26 default_config = 'rainbowstream/colorset/default.json'
27 rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json'
28 load_config(default_config)
29 load_config(rainbow_config)