fix sqlalchemy bug
authorVu Nhat Minh <vunhat_minh@dwango.co.jp>
Thu, 3 Jul 2014 07:22:21 +0000 (16:22 +0900)
committerVu Nhat Minh <vunhat_minh@dwango.co.jp>
Thu, 3 Jul 2014 07:22:21 +0000 (16:22 +0900)
rainbowstream/config.py
rainbowstream/draw.py
rainbowstream/rainbow.py

index 697361d5369adfe51bba161fa88599a9d8f23914..183bfe35e84c2b9a604c5847fc2ca81b22b24505 100644 (file)
@@ -18,33 +18,31 @@ def load_config(filepath):
     """
     Load config from filepath
     """
-    try:
-        with open(filepath) as f:
-            content = ''.join(f.readlines())
+    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)
-            while match:
-                content = content[:match.start()] + content[match.end():]
-                match = comment_re.search(content)
-        return json.loads(content)
-    except IOError:
-        return None
+    return json.loads(content)
 
 # Load default colorset
 c = {}
 default_config = 'rainbowstream/colorset/default.json'
 data = load_config(default_config)
-if data:
-    for d in data:
-        c[d] = data[d]
-db.theme_store('default')
+for d in data:
+    c[d] = data[d]
+c['theme'] = 'default'
 # Load user's colorset
 rainbow_config = os.environ.get(
     'HOME',
     os.environ.get(
         'USERPROFILE',
         '')) + os.sep + '.rainbow_config.json'
-data = load_config(rainbow_config)
-if data:
+try:
+    data = load_config(rainbow_config)
     for d in data:
         c[d] = data[d]
-    db.theme_update('user')
+    c['theme'] = 'custom'
+except:
+    pass
index ff931ce373c8bd2e710c49b0a8c3f5783f8d1fc2..148fc5884456378dfa81f376f6e8bec921510f39 100644 (file)
@@ -14,7 +14,6 @@ from .config import *
 from .db import *
 
 db = RainbowDB()
-cur_theme = None
 
 def check_theme():
     """
@@ -22,17 +21,17 @@ def check_theme():
     """
     exists = db.theme_query()
     themes = [t.theme_name for t in exists]
-    if cur_theme != themes[0]:
-        cur_theme = themes[0]
+    if c['theme'] != themes[0]:
+        c['theme'] = themes[0]
         # Determine path
-        if cur_theme == 'user':
+        if c['theme'] == 'custom':
             config = os.environ.get(
                 'HOME',
                 os.environ.get(
                 'USERPROFILE',
                 '')) + os.sep + '.rainbow_config.json'
         else:
-            config = 'rainbowstream/colorset/'+cur_theme+'.json'
+            config = 'rainbowstream/colorset/'+c['theme']+'.json'
         # Load new config
         data = load_config(config)
         if data:
index 96d2f562bf162707f8308bbff77129331f9930ea..ed3d07fdf61cb0bb658a9560bf8f4651090ccc3f 100644 (file)
@@ -139,8 +139,8 @@ def get_decorated_name():
 
     files = os.listdir('rainbowstream/colorset')
     themes = [f.split('.')[0] for f in files if f.split('.')[-1] == 'json']
-    themes += ['user']
     g['themes'] = themes
+    db.theme_store(c['theme'])
 
 
 def switch():
@@ -769,19 +769,23 @@ def theme():
     """
     if not g['stuff']:
         # List themes
-        line = ' ' * 2 + light_yellow('* ')
         for theme in g['themes']:
+            line = ''
             # Detect custom config
-            if theme == 'user':
+            if theme == 'custom':
                 line += light_magenta('custom')
                 exists = db.theme_query()
                 themes = [t.theme_name for t in exists]
-                if themes[0] == 'user':
+                if themes[0] == 'custom':
                     line += light_magenta(' (applied)')
                 else:
                     line += light_magenta(' (not specified)')
             else:
                 line += light_magenta(theme)
+            if c['theme'] == theme :
+                line = ' '*2 + light_yellow('* ') + line
+            else:
+                line = ' '*4 + line
             printNicely(line)
     else:
         # Change theme
@@ -793,7 +797,7 @@ def theme():
                 for nc in new_config:
                     c[nc] = new_config[nc]
             # Update db
-            theme_update(g['stuff'])
+            db.theme_update(g['stuff'])
             g['decorated_name'] = color_func(
                 c['DECORATED_NAME'])(
                 '[@' + g['original_name'] + ']: ')