From 0a0ee6dbc4993c1c9d21c101f7df53517af120e4 Mon Sep 17 00:00:00 2001 From: Vu Nhat Minh Date: Wed, 2 Jul 2014 17:16:40 +0900 Subject: [PATCH] full json --- rainbowstream/colorset/default.json | 20 +++++++++ rainbowstream/config.py | 67 ++++++++++------------------- 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/rainbowstream/colorset/default.json b/rainbowstream/colorset/default.json index ad4031e..7d7aad7 100644 --- a/rainbowstream/colorset/default.json +++ b/rainbowstream/colorset/default.json @@ -1,4 +1,24 @@ { + // 'search': max search record + "SEARCH_MAX_RECORD" : 5, + // 'home': default number of home's tweets + "HOME_TWEET_NUM" : 5, + // 'allrt': default number of retweets + "RETWEETS_SHOW_NUM" : 5, + // 'inbox','sent': default number of direct message + "MESSAGES_DISPLAY" : 5, + // 'trend': max trending topics + "TREND_MAX" : 10, + // 'switch': Filter and Ignore list ex: ['@fat','@mdo'] + "ONLY_LIST" : [], + "IGNORE_LIST" : [], + // Autocomplete history file name + "HISTORY_FILENAME" : "completer.hist", + // Image config + "IMAGE_SHIFT" : "10", + "IMAGE_MAX_HEIGHT" : "40", + + // Color config "TWEET" : { "nick" : "grey", "clock" : "grey", diff --git a/rainbowstream/config.py b/rainbowstream/config.py index b7376af..55fea3c 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -1,52 +1,29 @@ -from .colors import * import json import os import os.path -# 'search': max search record -SEARCH_MAX_RECORD = 5 -# 'home': default number of home's tweets -HOME_TWEET_NUM = 5 -# 'allrt': default number of retweets -RETWEETS_SHOW_NUM = 5 -# 'inbox','sent': default number of direct message -MESSAGES_DISPLAY = 5 -# 'trend': max trending topics -TREND_MAX = 10 -# 'switch': Filter and Ignore list ex: ['@fat','@mdo'] -ONLY_LIST = [] -IGNORE_LIST = [] - -# Autocomplete history file name -HISTORY_FILENAME = 'completer.hist' - -USER_DOMAIN = 'userstream.twitter.com' -PUBLIC_DOMAIN = 'stream.twitter.com' -SITE_DOMAIN = 'sitestream.twitter.com' -DOMAIN = USER_DOMAIN - -# Image config -IMAGE_SHIFT = 10 -IMAGE_MAX_HEIGHT = 40 - -# Load colorset -default_colorset = 'rainbowstream/colorset/default.json' -try: - if os.path.exists(default_colorset): - data = json.load(open(default_colorset)) +# Regular expression for comments +comment_re = re.compile( + '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?', + re.DOTALL | re.MULTILINE +) + +def load_config(filepath): + try: + 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) + data = json.loads(content) for d in data: - locals()[d] = data[d] -except: - pass + globals()[d] = data[d] + except: + pass -# Load json config +# Load colorset +default_config = 'rainbowstream/colorset/default.json' rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json' -try: - if os.path.exists(rainbow_config): - data = json.load(open(rainbow_config)) - for d in data: - locals()[d] = data[d] -except: - pass - - +load_config(default_config) +load_config(rainbow_config) -- 2.25.1