From 9fe9ba4743092a6b34e37946870aa2fb3d8c006c Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Wed, 21 Sep 2016 21:14:53 +0300 Subject: [PATCH] default profile fix --- toxygen/history.py | 1 + toxygen/settings.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/toxygen/history.py b/toxygen/history.py index 4134d54..d83c8f9 100644 --- a/toxygen/history.py +++ b/toxygen/history.py @@ -160,6 +160,7 @@ class History: db.close() def unlock_db(self): + print('Unlocking db...') connection = dbapi2.connect(self._name) connection.commit() connection.close() diff --git a/toxygen/settings.py b/toxygen/settings.py index 3623d69..daca665 100644 --- a/toxygen/settings.py +++ b/toxygen/settings.py @@ -49,9 +49,9 @@ class Settings(dict, Singleton): @staticmethod def get_auto_profile(): - path = Settings.get_default_path() + 'toxygen.json' - if os.path.isfile(path): - with open(path) as fl: + p = Settings.get_default_path() + 'toxygen.json' + if os.path.isfile(p): + with open(p) as fl: data = fl.read() auto = json.loads(data) if 'path' in auto and 'name' in auto: @@ -61,9 +61,12 @@ class Settings(dict, Singleton): @staticmethod def set_auto_profile(path, name): p = Settings.get_default_path() + 'toxygen.json' - with open(p) as fl: - data = fl.read() - data = json.loads(data) + if os.path.isfile(p): + with open(p) as fl: + data = fl.read() + data = json.loads(data) + else: + data = {} data['path'] = str(path) data['name'] = str(name) with open(p, 'w') as fl: @@ -72,9 +75,12 @@ class Settings(dict, Singleton): @staticmethod def reset_auto_profile(): p = Settings.get_default_path() + 'toxygen.json' - with open(p) as fl: - data = fl.read() - data = json.loads(data) + if os.path.isfile(p): + with open(p) as fl: + data = fl.read() + data = json.loads(data) + else: + data = {} if 'path' in data: del data['path'] del data['name']