From 1c8a5082c78a425b81185ca26067445b3b28b484 Mon Sep 17 00:00:00 2001 From: Orakaro Date: Fri, 4 Jul 2014 23:19:52 +0900 Subject: [PATCH] set theme as default --- MANIFEST.in | 1 - rainbowstream/config.py | 20 ++++++++++++++++++-- rainbowstream/rainbow.py | 8 +++++++- setup.py | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 4e90fb0..08270fc 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,3 @@ include README.rst include rainbowstream/image.c -include rainbowstream/consumer.pyc recursive-include rainbowstream/colorset *.json diff --git a/rainbowstream/config.py b/rainbowstream/config.py index bc541a9..e75ec67 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -3,7 +3,6 @@ import re import os import os.path - # Regular expression for comments comment_re = re.compile( '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?', @@ -23,13 +22,30 @@ def load_config(filepath): match = comment_re.search(content) return json.loads(content) -# Load default colorset +# 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 rainbow_config = os.environ.get( 'HOME', diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index b704287..29fbc53 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -781,6 +781,12 @@ def theme(): else: line = ' '*4 + line printNicely(line) + elif g['stuff'] == 'current_as_default': + path = os.path.dirname(__file__) + '/colorset/init' + f = open(path,'w') + f.write(c['theme']) + f.close() + printNicely(light_green('Okay it will be applied from next time :)')) else: # Change theme try: @@ -1060,7 +1066,7 @@ def listen(): ['@'], # unblock ['@'], # report [], # cal - g['themes'], # theme + g['themes'] + ['current_as_default'], # theme [], # help [], # clear [], # quit diff --git a/setup.py b/setup.py index 0db589b..73080a4 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -version = '0.1.10' +version = '0.2.0' install_requires = [ "SQLAlchemy", -- 2.25.1