fix sqlalchemy bug
[rainbowstream.git] / rainbowstream / config.py
CommitLineData
44d70096 1import json
72c02928 2import re
44d70096
VNM
3import os
4import os.path
6fa09c14 5
4cf86720
VNM
6from .db import *
7
8db = RainbowDB()
9
0a0ee6db
VNM
10# Regular expression for comments
11comment_re = re.compile(
12 '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
13 re.DOTALL | re.MULTILINE
14)
15
c075e6dc 16
0a0ee6db 17def load_config(filepath):
92be926e
VNM
18 """
19 Load config from filepath
20 """
ddb1e615
VNM
21 with open(filepath) as f:
22 content = ''.join(f.readlines())
23 match = comment_re.search(content)
24 while match:
25 content = content[:match.start()] + content[match.end():]
0a0ee6db 26 match = comment_re.search(content)
ddb1e615 27 return json.loads(content)
6fa09c14 28
632c6fa5
O
29# Load default colorset
30c = {}
0a0ee6db 31default_config = 'rainbowstream/colorset/default.json'
632c6fa5 32data = load_config(default_config)
ddb1e615
VNM
33for d in data:
34 c[d] = data[d]
35c['theme'] = 'default'
632c6fa5 36# Load user's colorset
c075e6dc
O
37rainbow_config = os.environ.get(
38 'HOME',
39 os.environ.get(
40 'USERPROFILE',
41 '')) + os.sep + '.rainbow_config.json'
ddb1e615
VNM
42try:
43 data = load_config(rainbow_config)
a5301bc0
VNM
44 for d in data:
45 c[d] = data[d]
ddb1e615
VNM
46 c['theme'] = 'custom'
47except:
48 pass