generate config file by default
authorOrakaro <nhatminh_179@hotmail.com>
Tue, 15 Jul 2014 14:49:28 +0000 (23:49 +0900)
committerOrakaro <nhatminh_179@hotmail.com>
Tue, 15 Jul 2014 14:49:28 +0000 (23:49 +0900)
rainbowstream/colorset/config [new file with mode: 0644]
rainbowstream/colorset/default.json
rainbowstream/config.py
rainbowstream/draw.py
rainbowstream/rainbow.py
setup.py

diff --git a/rainbowstream/colorset/config b/rainbowstream/colorset/config
new file mode 100644 (file)
index 0000000..21ff30f
--- /dev/null
@@ -0,0 +1,28 @@
+{
+    // Themes
+    "THEME" : "monokai",
+    // '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,
+    // List home timeline max
+    "LIST_MAX" : 5,
+    // '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,
+    // Stream config
+    "USER_DOMAIN" : "userstream.twitter.com",
+    "PUBLIC_DOMAIN" : "stream.twitter.com",
+    "SITE_DOMAIN" : "sitestream.twitter.com"
+}
index f2b23a4d35293452ad9691ec834061934efd555f..134891d9f187429889262d24643f799aa8fd0d96 100644 (file)
@@ -1,29 +1,4 @@
 {
 {
-    // '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,
-    // List home timeline max
-    "LIST_MAX" : 5,
-    // '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,
-    // Stream config
-    "USER_DOMAIN" : "userstream.twitter.com",
-    "PUBLIC_DOMAIN" : "stream.twitter.com",
-    "SITE_DOMAIN" : "sitestream.twitter.com",
-
     /* Color config
     There are 16 basic colors supported :
         * default
     /* Color config
     There are 16 basic colors supported :
         * default
@@ -43,8 +18,6 @@
         * light_cyan
         * white
     and 256 colors from term_0 to term_255
         * light_cyan
         * white
     and 256 colors from term_0 to term_255
-    Color code can be reference at
-    http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
      */
 
     "DECORATED_NAME" : "grey",
      */
 
     "DECORATED_NAME" : "grey",
index b17a0e2f46734a9a91cb28c2d1d580bffcfe2de1..de15655cfe3c0890334a32cb79d46c810bb9ee07 100644 (file)
@@ -2,6 +2,7 @@ import json
 import re
 import os
 import os.path
 import re
 import os
 import os.path
+from collections import OrderedDict
 
 # Regular expression for comments
 comment_re = re.compile(
 
 # Regular expression for comments
 comment_re = re.compile(
@@ -9,7 +10,6 @@ comment_re = re.compile(
     re.DOTALL | re.MULTILINE
 )
 
     re.DOTALL | re.MULTILINE
 )
 
-
 def load_config(filepath):
     """
     Load config from filepath
 def load_config(filepath):
     """
     Load config from filepath
@@ -20,34 +20,12 @@ def load_config(filepath):
         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)
+    return json.loads(content, object_pairs_hook=OrderedDict)
 
 # Config dictionary
 c = {}
 
 # 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
+
+# Load user's config
 rainbow_config = os.environ.get(
     'HOME',
     os.environ.get(
 rainbow_config = os.environ.get(
     'HOME',
     os.environ.get(
@@ -57,6 +35,15 @@ try:
     data = load_config(rainbow_config)
     for d in data:
         c[d] = data[d]
     data = load_config(rainbow_config)
     for d in data:
         c[d] = data[d]
-    c['theme'] = 'custom'
+except:
+    pass
+
+# Load default theme
+theme_file = os.path.dirname(
+    __file__) + '/colorset/' + c['THEME'] + '.json'
+try:
+    data = load_config(theme_file)
+    for d in data:
+        c[d] = data[d]
 except:
     pass
 except:
     pass
index 7d4de2efed778bdb7722e6f0648885bffe3bceb2..a24ce03d90f57a6d96d824c4fdadb90b10e7cb66 100644 (file)
@@ -118,17 +118,10 @@ def check_theme():
     """
     exists = db.theme_query()
     themes = [t.theme_name for t in exists]
     """
     exists = db.theme_query()
     themes = [t.theme_name for t in exists]
-    if c['theme'] != themes[0]:
-        c['theme'] = themes[0]
-        # Determine path
-        if c['theme'] == 'custom':
-            config = os.environ.get(
-                'HOME',
-                os.environ.get('USERPROFILE',
-                               '')) + os.sep + '.rainbow_config.json'
-        else:
-            config = os.path.dirname(
-                __file__) + '/colorset/' + c['theme'] + '.json'
+    if c['THEME'] != themes[0]:
+        c['THEME'] = themes[0]
+        config = os.path.dirname(
+            __file__) + '/colorset/' + c['THEME'] + '.json'
         # Load new config
         data = load_config(config)
         if data:
         # Load new config
         data = load_config(config)
         if data:
index 8072114b313f66137efb40e01602f500d96c0e63..5ce703ab5b6a35a51d7dc421845b92c9cd7b56c4 100644 (file)
@@ -11,6 +11,7 @@ import argparse
 import time
 import requests
 import webbrowser
 import time
 import requests
 import webbrowser
+import json
 
 from twitter.stream import TwitterStream, Timeout, HeartbeatTimeout, Hangup
 from twitter.api import *
 
 from twitter.stream import TwitterStream, Timeout, HeartbeatTimeout, Hangup
 from twitter.api import *
@@ -144,9 +145,8 @@ def get_decorated_name():
 
     files = os.listdir(os.path.dirname(__file__) + '/colorset')
     themes = [f.split('.')[0] for f in files if f.split('.')[-1] == 'json']
 
     files = os.listdir(os.path.dirname(__file__) + '/colorset')
     themes = [f.split('.')[0] for f in files if f.split('.')[-1] == 'json']
-    themes += ['custom']
     g['themes'] = themes
     g['themes'] = themes
-    db.theme_store(c['theme'])
+    db.theme_store(c['THEME'])
 
 
 def switch():
 
 
 def switch():
@@ -1131,32 +1131,31 @@ def theme():
     if not g['stuff']:
         # List themes
         for theme in g['themes']:
     if not g['stuff']:
         # List themes
         for theme in g['themes']:
-            line = ''
-            # Detect custom config
-            if theme == 'custom':
-                line += light_magenta('custom')
-                custom_path = os.environ.get(
-                    'HOME',
-                    os.environ.get('USERPROFILE',
-                                   '')) + os.sep + '.rainbow_config.json'
-                if not os.path.exists(custom_path):
-                    line += light_magenta(
-                        ' (create your own config file at ~/.rainbow_config.json)')
-                else:
-                    line += light_magenta(' (loaded)')
-            else:
-                line += light_magenta(theme)
-            if c['theme'] == theme:
+            line = light_magenta(theme)
+            if c['THEME'] == theme:
                 line = ' ' * 2 + light_yellow('* ') + line
             else:
                 line = ' ' * 4 + line
             printNicely(line)
     elif g['stuff'] == 'current_as_default':
                 line = ' ' * 2 + light_yellow('* ') + line
             else:
                 line = ' ' * 4 + line
             printNicely(line)
     elif g['stuff'] == 'current_as_default':
-        # Set default
-        path = os.path.dirname(__file__) + '/colorset/init'
-        f = open(path, 'w')
-        f.write(c['theme'])
-        f.close()
+        # Set as default
+        def fixup(adict, k, v):
+            for key in adict.keys():
+                if key == k:
+                    adict[key] = v
+                elif type(adict[key]) is dict:
+                    fixup(adict[key], k, v)
+        # Modify
+        path = os.environ.get(
+            'HOME',
+            os.environ.get(
+                'USERPROFILE',
+                '')) + os.sep + '.rainbow_config.json'
+        data = load_config(rainbow_config)
+        fixup(data, 'THEME', c['THEME'])
+        # Save
+        with open(path, 'w') as out:
+            json.dump(data, out, indent = 4)
         os.system('chmod 777 ' + path)
         printNicely(light_green('Okay it will be applied from next time :)'))
     else:
         os.system('chmod 777 ' + path)
         printNicely(light_green('Okay it will be applied from next time :)'))
     else:
@@ -1177,17 +1176,14 @@ def theme():
                     c[nc] = new_config[nc]
             # Update db and reset colors
             db.theme_update(g['stuff'])
                     c[nc] = new_config[nc]
             # Update db and reset colors
             db.theme_update(g['stuff'])
-            c['theme'] = g['stuff']
+            c['THEME'] = g['stuff']
             reset_cycle()
             g['decorated_name'] = color_func(
                 c['DECORATED_NAME'])(
                 '[@' + g['original_name'] + ']: ')
             printNicely(green('Theme changed.'))
         except:
             reset_cycle()
             g['decorated_name'] = color_func(
                 c['DECORATED_NAME'])(
                 '[@' + g['original_name'] + ']: ')
             printNicely(green('Theme changed.'))
         except:
-            if g['stuff'] == 'custom':
-                printNicely(red('~/.rainbow_config.json is not exists!'))
-            else:
-                printNicely(red('No such theme exists.'))
+            printNicely(red('No such theme exists.'))
 
 
 def help_discover():
 
 
 def help_discover():
@@ -1612,7 +1608,7 @@ def stream(domain, args, name='Rainbow Stream'):
     art_dict = {
         c['USER_DOMAIN']: name,
         c['PUBLIC_DOMAIN']: args.track_keywords,
     art_dict = {
         c['USER_DOMAIN']: name,
         c['PUBLIC_DOMAIN']: args.track_keywords,
-        c['SITE_DOMAIN']: 'Site Stream',
+        c['SITE_DOMAIN']: name,
     }
     if g['ascii_art']:
         ascii_art(art_dict[domain])
     }
     if g['ascii_art']:
         ascii_art(art_dict[domain])
index 294fd8672795dec3b2c9725f6edb180261ec376c..0d99cd7232b927ca13f63c8545f6acb82b7350fc 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,8 +1,10 @@
 from setuptools import setup, find_packages
 from setuptools import setup, find_packages
-import sys
+import os, sys
 
 
-version = '0.3.4'
+# Bumped version
+version = '0.3.5'
 
 
+# Require
 install_requires = [
     "python-dateutil",
     "requests",
 install_requires = [
     "python-dateutil",
     "requests",
@@ -11,9 +13,21 @@ install_requires = [
     "twitter",
     "Pillow",
 ]
     "twitter",
     "Pillow",
 ]
+# Python 3 doesn't hava pysqlite
 if sys.version[0] == "2":
     install_requires += ["pysqlite"]
 
 if sys.version[0] == "2":
     install_requires += ["pysqlite"]
 
+# Copy default config if not exists
+default = os.environ.get(
+    'HOME',
+    os.environ.get(
+        'USERPROFILE',
+        '')) + os.sep + '.rainbow_config.json'
+if not os.path.isfile(default):
+    cmd = 'cp rainbowstream/colorset/config ' + default
+    os.system(cmd)
+
+# Setup
 setup(name='rainbowstream',
       version=version,
       description="A smart and nice Twitter client on terminal.",
 setup(name='rainbowstream',
       version=version,
       description="A smart and nice Twitter client on terminal.",
@@ -25,8 +39,6 @@ setup(name='rainbowstream',
           "Natural Language :: English",
           "Operating System :: OS Independent",
           "Programming Language :: Python :: 2.7",
           "Natural Language :: English",
           "Operating System :: OS Independent",
           "Programming Language :: Python :: 2.7",
-          "Programming Language :: Python :: 3.2",
-          "Programming Language :: Python :: 3.3",
           "Programming Language :: Python :: 3.4",
           "Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries",
           "Topic :: Utilities",
           "Programming Language :: Python :: 3.4",
           "Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries",
           "Topic :: Utilities",