From 8619b00b13f74ed01902a121c3688424b5983397 Mon Sep 17 00:00:00 2001 From: Orakaro Date: Sat, 26 Jul 2014 21:31:16 +0900 Subject: [PATCH] delete db file if exist on startup --- rainbowstream/config.py | 30 +++++------------------------- rainbowstream/db.py | 5 +++-- setup.py | 10 +++------- 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/rainbowstream/config.py b/rainbowstream/config.py index 4131295..c27812e 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -42,11 +42,7 @@ def get_all_config(): """ Get all config """ - path = os.environ.get( - 'HOME', - os.environ.get( - 'USERPROFILE', - '')) + os.sep + '.rainbow_config.json' + path = os.path.expanduser("~") + os.sep + '.rainbow_config.json' data = load_config(path) # Hard to set from prompt data.pop('ONLY_LIST', None) @@ -86,11 +82,7 @@ def set_config(key, value): elif value.lower() == 'false': value = False # Fix up - path = os.environ.get( - 'HOME', - os.environ.get( - 'USERPROFILE', - '')) + os.sep + '.rainbow_config.json' + path = os.path.expanduser("~") + os.sep + '.rainbow_config.json' data = {} try: data = load_config(path) @@ -113,11 +105,7 @@ def delete_config(key): """ Delete a config key """ - path = os.environ.get( - 'HOME', - os.environ.get( - 'USERPROFILE', - '')) + os.sep + '.rainbow_config.json' + path = os.path.expanduser("~") + os.sep + '.rainbow_config.json' data = load_config(path) # Drop key if key in data and key in c: @@ -139,11 +127,7 @@ def reload_config(): """ Reload config """ - rainbow_config = os.environ.get( - 'HOME', - os.environ.get( - 'USERPROFILE', - '')) + os.sep + '.rainbow_config.json' + rainbow_config = os.path.expanduser("~") + os.sep + '.rainbow_config.json' try: data = load_config(rainbow_config) for d in data: @@ -166,11 +150,7 @@ def init_config(): except: pass # Load user's config - rainbow_config = os.environ.get( - 'HOME', - os.environ.get( - 'USERPROFILE', - '')) + os.sep + '.rainbow_config.json' + rainbow_config = os.path.expanduser("~") + os.sep + '.rainbow_config.json' try: data = load_config(rainbow_config) for d in data: diff --git a/rainbowstream/db.py b/rainbowstream/db.py index 1714005..8f4ce40 100644 --- a/rainbowstream/db.py +++ b/rainbowstream/db.py @@ -12,8 +12,9 @@ class RainbowDB(): """ Init DB """ - if not os.path.isfile('rainbow.db'): - init_db() + if os.path.isfile('rainbow.db'): + os.system('rm -rf rainbow.db') + init_db() self.engine = create_engine('sqlite:///rainbow.db', echo=False) diff --git a/setup.py b/setup.py index 73573d0..dc7fa6f 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,8 @@ from setuptools import setup, find_packages -import os, sys +import os, os.path, sys # Bumped version -version = '0.4.9' +version = '0.4.10' # Require install_requires = [ @@ -19,11 +19,7 @@ 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' +default = os.path.expanduser("~") + os.sep + '.rainbow_config.json' if not os.path.isfile(default): cmd = 'cp rainbowstream/colorset/config ' + default os.system(cmd) -- 2.25.1