X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=blobdiff_plain;f=rainbowstream%2Fconfig.py;h=a5e542d5afcd492338ae2ea7f568b5ff2c4d5c2e;hp=c079d87b85e38d4526aa45488227402c8305cb91;hb=f75930c6e0b0ec505732b758d414162a8bebdece;hpb=35abe765b895963fbdf1405641baf97341955a9c diff --git a/rainbowstream/config.py b/rainbowstream/config.py index c079d87..a5e542d 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -2,7 +2,7 @@ import json import re import os import os.path -from twitter.util import printNicely + # Regular expression for comments comment_re = re.compile( @@ -10,26 +10,36 @@ comment_re = re.compile( re.DOTALL | re.MULTILINE ) + def load_config(filepath): - try: - with open(filepath) as f: - content = ''.join(f.readlines()) + """ + Load config from filepath + """ + with open(filepath) as f: + content = ''.join(f.readlines()) + match = comment_re.search(content) + while match: + content = content[:match.start()] + content[match.end():] match = comment_re.search(content) - while match: - content = content[:match.start()] + content[match.end():] - match = comment_re.search(content) - data = json.loads(content) - for d in data: - globals()[d] = data[d] - except: - pass - -# Image config -IMAGE_SHIFT = 10 -IMAGE_MAX_HEIGHT = 40 + return json.loads(content) -# Load colorset +# Load default colorset +c = {} default_config = 'rainbowstream/colorset/default.json' -rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json' -load_config(default_config) -load_config(rainbow_config) +data = load_config(default_config) +for d in data: + c[d] = data[d] +c['theme'] = 'default' +# Load user's colorset +rainbow_config = os.environ.get( + 'HOME', + os.environ.get( + 'USERPROFILE', + '')) + os.sep + '.rainbow_config.json' +try: + data = load_config(rainbow_config) + for d in data: + c[d] = data[d] + c['theme'] = 'custom' +except: + pass