c079d87b85e38d4526aa45488227402c8305cb91
[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 try:
15 with open(filepath) as f:
16 content = ''.join(f.readlines())
17 match = comment_re.search(content)
18 while match:
19 content = content[:match.start()] + content[match.end():]
20 match = comment_re.search(content)
21 data = json.loads(content)
22 for d in data:
23 globals()[d] = data[d]
24 except:
25 pass
26
27 # Image config
28 IMAGE_SHIFT = 10
29 IMAGE_MAX_HEIGHT = 40
30
31 # Load colorset
32 default_config = 'rainbowstream/colorset/default.json'
33 rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json'
34 load_config(default_config)
35 load_config(rainbow_config)