add 256 RGB supported
[rainbowstream.git] / rainbowstream / config.py
CommitLineData
44d70096 1import json
72c02928 2import re
44d70096
VNM
3import os
4import os.path
72c02928 5from twitter.util import printNicely
6fa09c14 6
0a0ee6db
VNM
7# Regular expression for comments
8comment_re = re.compile(
9 '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
10 re.DOTALL | re.MULTILINE
11)
12
13def load_config(filepath):
92be926e
VNM
14 """
15 Load config from filepath
16 """
0a0ee6db
VNM
17 try:
18 with open(filepath) as f:
19 content = ''.join(f.readlines())
20 match = comment_re.search(content)
21 while match:
22 content = content[:match.start()] + content[match.end():]
23 match = comment_re.search(content)
24 data = json.loads(content)
2e73187a 25 for d in data:
0a0ee6db
VNM
26 globals()[d] = data[d]
27 except:
28 pass
6fa09c14 29
0a0ee6db
VNM
30# Load colorset
31default_config = 'rainbowstream/colorset/default.json'
2e73187a 32rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json'
0a0ee6db
VNM
33load_config(default_config)
34load_config(rainbow_config)