Commit | Line | Data |
---|---|---|
44d70096 | 1 | import json |
72c02928 | 2 | import re |
44d70096 VNM |
3 | import os |
4 | import os.path | |
72c02928 | 5 | from twitter.util import printNicely |
6fa09c14 | 6 | |
0a0ee6db VNM |
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): | |
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 |
31 | default_config = 'rainbowstream/colorset/default.json' | |
2e73187a | 32 | rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json' |
0a0ee6db VNM |
33 | load_config(default_config) |
34 | load_config(rainbow_config) |