e2937ca329dceeeab2e4b6e7fc6fbf89aaa89f19
[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 DOMAIN = USER_DOMAIN
28
29 # Image config
30 IMAGE_SHIFT = 10
31 IMAGE_MAX_HEIGHT = 40
32
33 # Load colorset
34 default_config = 'rainbowstream/colorset/default.json'
35 rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json'
36 load_config(default_config)
37 load_config(rainbow_config)