X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=blobdiff_plain;f=rainbowstream%2Fconfig.py;h=e75ec6727ac00bc9716eb3da9088c5095c4e0cef;hp=a0cdc22e92922836adec9d3ab4fd30c1754999c6;hb=17bc529db5669ed5c44a3b74b13d9671ed2243b1;hpb=341c179445d0ff9c1c02f1d6616e01ece0d44d0b diff --git a/rainbowstream/config.py b/rainbowstream/config.py index a0cdc22..e75ec67 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -1,3 +1,61 @@ -# This is RainbowStream App info -CONSUMER_KEY = 'Xk1DGhR1FJa4xjg7GbdogzLJw' -CONSUMER_SECRET = 'SpHtDmbSGCSm55AAlIeb2PsD3kGEzxyo1325rJgrND5abeOh2T' +import json +import re +import os +import os.path + +# Regular expression for comments +comment_re = re.compile( + '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?', + re.DOTALL | re.MULTILINE +) + + +def load_config(filepath): + """ + 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) + return json.loads(content) + +# Config dictionary +c = {} +# Load default +default_config = os.path.dirname(__file__) + '/colorset/default.json' +data = load_config(default_config) +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] + 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' +try: + data = load_config(rainbow_config) + for d in data: + c[d] = data[d] + c['theme'] = 'custom' +except: + pass