default profile fix

This commit is contained in:
ingvar1995 2016-09-21 21:14:53 +03:00
parent 97ce2b9ceb
commit 9fe9ba4743
2 changed files with 16 additions and 9 deletions

View File

@ -160,6 +160,7 @@ class History:
db.close() db.close()
def unlock_db(self): def unlock_db(self):
print('Unlocking db...')
connection = dbapi2.connect(self._name) connection = dbapi2.connect(self._name)
connection.commit() connection.commit()
connection.close() connection.close()

View File

@ -49,9 +49,9 @@ class Settings(dict, Singleton):
@staticmethod @staticmethod
def get_auto_profile(): def get_auto_profile():
path = Settings.get_default_path() + 'toxygen.json' p = Settings.get_default_path() + 'toxygen.json'
if os.path.isfile(path): if os.path.isfile(p):
with open(path) as fl: with open(p) as fl:
data = fl.read() data = fl.read()
auto = json.loads(data) auto = json.loads(data)
if 'path' in auto and 'name' in auto: if 'path' in auto and 'name' in auto:
@ -61,9 +61,12 @@ class Settings(dict, Singleton):
@staticmethod @staticmethod
def set_auto_profile(path, name): def set_auto_profile(path, name):
p = Settings.get_default_path() + 'toxygen.json' p = Settings.get_default_path() + 'toxygen.json'
with open(p) as fl: if os.path.isfile(p):
data = fl.read() with open(p) as fl:
data = json.loads(data) data = fl.read()
data = json.loads(data)
else:
data = {}
data['path'] = str(path) data['path'] = str(path)
data['name'] = str(name) data['name'] = str(name)
with open(p, 'w') as fl: with open(p, 'w') as fl:
@ -72,9 +75,12 @@ class Settings(dict, Singleton):
@staticmethod @staticmethod
def reset_auto_profile(): def reset_auto_profile():
p = Settings.get_default_path() + 'toxygen.json' p = Settings.get_default_path() + 'toxygen.json'
with open(p) as fl: if os.path.isfile(p):
data = fl.read() with open(p) as fl:
data = json.loads(data) data = fl.read()
data = json.loads(data)
else:
data = {}
if 'path' in data: if 'path' in data:
del data['path'] del data['path']
del data['name'] del data['name']