X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=blobdiff_plain;f=rainbowstream%2Fconfig.py;h=b17a0e2f46734a9a91cb28c2d1d580bffcfe2de1;hp=697361d5369adfe51bba161fa88599a9d8f23914;hb=22592b9a295c8f96ec2305bb0dccab05aeed92aa;hpb=8394e34ba2fb669ba12071835166b6a32fa0cfe1 diff --git a/rainbowstream/config.py b/rainbowstream/config.py index 697361d..b17a0e2 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -3,10 +3,6 @@ import re import os import os.path -from .db import * - -db = RainbowDB() - # Regular expression for comments comment_re = re.compile( '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?', @@ -18,33 +14,49 @@ def load_config(filepath): """ Load config from filepath """ - try: - with open(filepath) as f: - content = ''.join(f.readlines()) + 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) - return json.loads(content) - except IOError: - return None + return json.loads(content) -# Load default colorset +# Config dictionary c = {} -default_config = 'rainbowstream/colorset/default.json' +# Load default +default_config = os.path.dirname(__file__) + '/colorset/default.json' data = load_config(default_config) -if data: +for d in data: + c[d] = data[d] +c['theme'] = 'default' +# Load init if exist +try: + path = os.path.dirname(__file__) + '/colorset/init' + f = open(path) + lines = f.readlines() + if len(lines) > 1: + raise Exception('More than 1 default theme') + theme_name = lines[0].strip() + default_config = os.path.dirname( + __file__) + '/colorset/' + theme_name + '.json' + data = load_config(default_config) for d in data: c[d] = data[d] -db.theme_store('default') + c['theme'] = theme_name + f.close() +except: + pass # Load user's colorset rainbow_config = os.environ.get( 'HOME', os.environ.get( 'USERPROFILE', '')) + os.sep + '.rainbow_config.json' -data = load_config(rainbow_config) -if data: +try: + data = load_config(rainbow_config) for d in data: c[d] = data[d] - db.theme_update('user') + c['theme'] = 'custom' +except: + pass