default config file moved to app dir
This commit is contained in:
parent
1a9db79ca2
commit
3194099f59
1 changed files with 14 additions and 35 deletions
|
@ -49,7 +49,7 @@ class Settings(dict, Singleton):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_auto_profile():
|
def get_auto_profile():
|
||||||
p = Settings.get_default_path() + 'toxygen.json'
|
p = Settings.get_global_settings_path()
|
||||||
if os.path.isfile(p):
|
if os.path.isfile(p):
|
||||||
with open(p) as fl:
|
with open(p) as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
|
@ -60,7 +60,7 @@ 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_global_settings_path()
|
||||||
if os.path.isfile(p):
|
if os.path.isfile(p):
|
||||||
with open(p) as fl:
|
with open(p) as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
|
@ -74,7 +74,7 @@ class Settings(dict, Singleton):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reset_auto_profile():
|
def reset_auto_profile():
|
||||||
p = Settings.get_default_path() + 'toxygen.json'
|
p = Settings.get_global_settings_path()
|
||||||
if os.path.isfile(p):
|
if os.path.isfile(p):
|
||||||
with open(p) as fl:
|
with open(p) as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
|
@ -89,15 +89,8 @@ class Settings(dict, Singleton):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_active_profile(path, name):
|
def is_active_profile(path, name):
|
||||||
path = path + name + '.tox'
|
path = path + name + '.lock'
|
||||||
settings = Settings.get_default_path() + 'toxygen.json'
|
return os.path.isfile(path)
|
||||||
if os.path.isfile(settings):
|
|
||||||
with open(settings) as fl:
|
|
||||||
data = fl.read()
|
|
||||||
data = json.loads(data)
|
|
||||||
if 'active_profile' in data:
|
|
||||||
return path in data['active_profile']
|
|
||||||
return False
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_default_settings():
|
def get_default_settings():
|
||||||
|
@ -176,37 +169,19 @@ class Settings(dict, Singleton):
|
||||||
fl.write(text)
|
fl.write(text)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
path = Settings.get_default_path() + 'toxygen.json'
|
profile_path = ProfileHelper.get_path()
|
||||||
|
path = str(profile_path + str(self.name) + '.lock')
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
with open(path) as fl:
|
os.remove(path)
|
||||||
data = fl.read()
|
|
||||||
app_settings = json.loads(data)
|
|
||||||
try:
|
|
||||||
app_settings['active_profile'].remove(str(ProfileHelper.get_path() + self.name + '.tox'))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
data = json.dumps(app_settings)
|
|
||||||
with open(path, 'w') as fl:
|
|
||||||
fl.write(data)
|
|
||||||
|
|
||||||
def set_active_profile(self):
|
def set_active_profile(self):
|
||||||
"""
|
"""
|
||||||
Mark current profile as active
|
Mark current profile as active
|
||||||
"""
|
"""
|
||||||
path = Settings.get_default_path() + 'toxygen.json'
|
|
||||||
if os.path.isfile(path):
|
|
||||||
with open(path) as fl:
|
|
||||||
data = fl.read()
|
|
||||||
app_settings = json.loads(data)
|
|
||||||
else:
|
|
||||||
app_settings = {}
|
|
||||||
if 'active_profile' not in app_settings:
|
|
||||||
app_settings['active_profile'] = []
|
|
||||||
profile_path = ProfileHelper.get_path()
|
profile_path = ProfileHelper.get_path()
|
||||||
app_settings['active_profile'].append(str(profile_path + str(self.name) + '.tox'))
|
path = str(profile_path + str(self.name) + '.lock')
|
||||||
data = json.dumps(app_settings)
|
|
||||||
with open(path, 'w') as fl:
|
with open(path, 'w') as fl:
|
||||||
fl.write(data)
|
fl.write('active')
|
||||||
|
|
||||||
def export(self, path):
|
def export(self, path):
|
||||||
text = json.dumps(self)
|
text = json.dumps(self)
|
||||||
|
@ -216,6 +191,10 @@ class Settings(dict, Singleton):
|
||||||
def update_path(self):
|
def update_path(self):
|
||||||
self.path = ProfileHelper.get_path() + self.name + '.json'
|
self.path = ProfileHelper.get_path() + self.name + '.json'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_global_settings_path():
|
||||||
|
return curr_directory() + '/toxygen.json'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_default_path():
|
def get_default_path():
|
||||||
if system() == 'Windows':
|
if system() == 'Windows':
|
||||||
|
|
Loading…
Reference in a new issue