From: Vu Nhat Minh Date: Thu, 3 Jul 2014 07:22:21 +0000 (+0900) Subject: fix sqlalchemy bug X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ddb1e61513a7c363b5eb7a12e8fb296077aaaaa0;p=rainbowstream.git fix sqlalchemy bug --- diff --git a/rainbowstream/config.py b/rainbowstream/config.py index 697361d..183bfe3 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -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 diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index ff931ce..148fc58 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -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: diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 96d2f56..ed3d07f 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -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'] + ']: ')