semaphore ater enter key are pushed
[rainbowstream.git] / rainbowstream / config.py
CommitLineData
44d70096 1import json
72c02928 2import re
44d70096
VNM
3import os
4import os.path
1f2f6159 5from collections import OrderedDict
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 """
ddb1e615
VNM
17 with open(filepath) as f:
18 content = ''.join(f.readlines())
19 match = comment_re.search(content)
20 while match:
21 content = content[:match.start()] + content[match.end():]
0a0ee6db 22 match = comment_re.search(content)
1f2f6159 23 return json.loads(content, object_pairs_hook=OrderedDict)
6fa09c14 24
1c8a5082 25# Config dictionary
632c6fa5 26c = {}
1f2f6159 27
687567eb 28# Load the initial config
29config = os.path.dirname(
30 __file__) + '/colorset/config'
31try:
32 data = load_config(config)
33 for d in data:
34 c[d] = data[d]
35except:
36 pass
37
1f2f6159 38# Load user's config
c075e6dc
O
39rainbow_config = os.environ.get(
40 'HOME',
41 os.environ.get(
42 'USERPROFILE',
43 '')) + os.sep + '.rainbow_config.json'
ddb1e615
VNM
44try:
45 data = load_config(rainbow_config)
a5301bc0
VNM
46 for d in data:
47 c[d] = data[d]
1f2f6159 48except:
8b8566d1 49 print('It seems that ~/.rainbow_config.json has wrong format :(')
1f2f6159
O
50
51# Load default theme
52theme_file = os.path.dirname(
53 __file__) + '/colorset/' + c['THEME'] + '.json'
54try:
55 data = load_config(theme_file)
56 for d in data:
57 c[d] = data[d]
ddb1e615
VNM
58except:
59 pass