autopep8
[rainbowstream.git] / rainbowstream / config.py
index 79458991e41467bfccbb852721c820f96790fd21..418afbb0a03411a1a563cdb5d479c4c5c43c4215 100644 (file)
@@ -1,25 +1,42 @@
-# Max Search record
-SEARCH_MAX_RECORD = 5
-# Default home tweet
-HOME_TWEET_NUM = 5
-# Default direct message's number
-MESSAGES_DISPLAY = 5
-# Max trending topics display
-TREND_MAX = 10
-# Autocomplete history
-HISTORY_FILENAME = 'completer.hist'
+import json
+import re
+import os
+import os.path
 
-# Stream Domain
-USER_DOMAIN = 'userstream.twitter.com'
-PUBLIC_DOMAIN = 'stream.twitter.com'
-SITE_DOMAIN = 'sitestream.twitter.com'
-# Actually called
-DOMAIN = USER_DOMAIN
+# Regular expression for comments
+comment_re = re.compile(
+    '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
+    re.DOTALL | re.MULTILINE
+)
 
-# Filter and Ignore list ex: ['@fat','@mdo']
-ONLY_LIST = []
-IGNORE_LIST = []
 
-# Image shift and size
-IMAGE_SHIFT = 10
-IMAGE_MAX_HEIGHT = 40
+def load_config(filepath):
+    """
+    Load config from 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)
+        return json.loads(content)
+    except:
+        pass
+
+# Load default colorset
+c = {}
+default_config = 'rainbowstream/colorset/default.json'
+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]