add 256 RGB supported
[rainbowstream.git] / rainbowstream / config.py
1 import json
2 import re
3 import os
4 import os.path
5 from twitter.util import printNicely
6
7 # Regular expression for comments
8 comment_re = re.compile(
9 '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
10 re.DOTALL | re.MULTILINE
11 )
12
13 def load_config(filepath):
14 """
15 Load config from filepath
16 """
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)
25 for d in data:
26 globals()[d] = data[d]
27 except:
28 pass
29
30 # Load colorset
31 default_config = 'rainbowstream/colorset/default.json'
32 rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json'
33 load_config(default_config)
34 load_config(rainbow_config)