full json
[rainbowstream.git] / rainbowstream / config.py
CommitLineData
44d70096
VNM
1import json
2import os
3import os.path
6fa09c14 4
0a0ee6db
VNM
5# Regular expression for comments
6comment_re = re.compile(
7 '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
8 re.DOTALL | re.MULTILINE
9)
10
11def 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)
2e73187a 20 for d in data:
0a0ee6db
VNM
21 globals()[d] = data[d]
22 except:
23 pass
6fa09c14 24
0a0ee6db
VNM
25# Load colorset
26default_config = 'rainbowstream/colorset/default.json'
2e73187a 27rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json'
0a0ee6db
VNM
28load_config(default_config)
29load_config(rainbow_config)