X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;ds=sidebyside;f=rainbowstream%2Fconfig.py;h=418afbb0a03411a1a563cdb5d479c4c5c43c4215;hb=c075e6dcf76153c0209b16e12771ae491f4b175a;hp=de49969846a83d7712b02c192de2b37057bd684e;hpb=92be926e9093ad23c463ba39c94047d883e779be;p=rainbowstream.git diff --git a/rainbowstream/config.py b/rainbowstream/config.py index de49969..418afbb 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -2,7 +2,6 @@ import json import re import os import os.path -from twitter.util import printNicely # Regular expression for comments comment_re = re.compile( @@ -10,6 +9,7 @@ comment_re = re.compile( re.DOTALL | re.MULTILINE ) + def load_config(filepath): """ Load config from filepath @@ -21,14 +21,22 @@ def load_config(filepath): 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] + return json.loads(content) except: pass -# 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] +# Load user's colorset +rainbow_config = os.environ.get( + 'HOME', + os.environ.get( + 'USERPROFILE', + '')) + os.sep + '.rainbow_config.json' +data = load_config(rainbow_config) +for d in data: + c[d] = data[d]