|
|
|
@ -17,7 +17,6 @@ LOG = logging.getLogger('settings')
|
|
|
|
|
|
|
|
|
|
def merge_args_into_settings(args, settings):
|
|
|
|
|
if args:
|
|
|
|
|
print(repr(args.__dict__.keys()))
|
|
|
|
|
if not hasattr(args, 'audio'):
|
|
|
|
|
LOG.warn('No audio ' +repr(args))
|
|
|
|
|
settings['audio'] = getattr(args, 'audio')
|
|
|
|
@ -131,17 +130,17 @@ class Settings(dict):
|
|
|
|
|
Settings of current profile + global app settings
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, toxes, path, app):
|
|
|
|
|
self._path = path
|
|
|
|
|
self._profile_path = path.replace('.json', '.tox')
|
|
|
|
|
def __init__(self, toxes, json_path, app):
|
|
|
|
|
self._toxes = toxes
|
|
|
|
|
self._app = app
|
|
|
|
|
self._path = app._path
|
|
|
|
|
self._args = app._args
|
|
|
|
|
self._oArgs = app._args
|
|
|
|
|
self._log = lambda l: LOG.log(self._oArgs.loglevel, l)
|
|
|
|
|
self._profile_path = app._path # json_path.replace('.json', '.tox')
|
|
|
|
|
|
|
|
|
|
self._settings_saved_event = Event()
|
|
|
|
|
path = json_path.replace('.tox', '.json')
|
|
|
|
|
if path and os.path.isfile(path):
|
|
|
|
|
try:
|
|
|
|
|
with open(path, 'rb') as fl:
|
|
|
|
@ -151,9 +150,9 @@ class Settings(dict):
|
|
|
|
|
info = json.loads(str(data, 'utf-8'))
|
|
|
|
|
LOG.debug('Parsed settings from: ' + str(path))
|
|
|
|
|
except Exception as ex:
|
|
|
|
|
title = 'Error opening/parsing settings file: '
|
|
|
|
|
text = title + path
|
|
|
|
|
LOG.error(title +str(ex))
|
|
|
|
|
title = f"Error opening/parsing settings file:"
|
|
|
|
|
text = title +f"\n{path}\n"
|
|
|
|
|
LOG.error(text +str(ex))
|
|
|
|
|
util_ui.message_box(text, title)
|
|
|
|
|
info = Settings.get_default_settings(app._args)
|
|
|
|
|
user_data.settings.clean_settings(info)
|
|
|
|
@ -161,7 +160,7 @@ class Settings(dict):
|
|
|
|
|
LOG.debug('get_default_settings for: ' + repr(path))
|
|
|
|
|
info = Settings.get_default_settings(app._args)
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(path):
|
|
|
|
|
if not path or not os.path.exists(path):
|
|
|
|
|
merge_args_into_settings(app._args, info)
|
|
|
|
|
else:
|
|
|
|
|
aC = self._changed(app._args, info)
|
|
|
|
@ -178,12 +177,16 @@ class Settings(dict):
|
|
|
|
|
merge_args_into_settings(app._args, info)
|
|
|
|
|
info['audio'] = getattr(app._args, 'audio')
|
|
|
|
|
info['video'] = getattr(app._args, 'video')
|
|
|
|
|
info['trace_enabled'] = getattr(app._args, 'trace_enabled')
|
|
|
|
|
if getattr(app._args, 'trace_enabled'):
|
|
|
|
|
info['trace_enabled'] = getattr(app._args, 'trace_enabled')
|
|
|
|
|
else:
|
|
|
|
|
LOG.warn("app._args, 'trace_enabled")
|
|
|
|
|
info['trace_enabled'] = False
|
|
|
|
|
super().__init__(info)
|
|
|
|
|
self._upgrade()
|
|
|
|
|
|
|
|
|
|
LOG.info('Parsed settings from: ' + str(path))
|
|
|
|
|
ex = f"self=id(self) {self!r}"
|
|
|
|
|
ex = f"self=id(self) {self}"
|
|
|
|
|
LOG.debug(ex)
|
|
|
|
|
|
|
|
|
|
self.save()
|
|
|
|
@ -206,10 +209,16 @@ class Settings(dict):
|
|
|
|
|
text = bytes(self._toxes.pass_encrypt(bytes(text, 'utf-8')))
|
|
|
|
|
else:
|
|
|
|
|
text = bytes(text, 'utf-8')
|
|
|
|
|
if not self._path:
|
|
|
|
|
#?
|
|
|
|
|
self._path = os.path.join(get_user_config_path(), 'toxygen.json')
|
|
|
|
|
tmp = self._path + str(os.getpid())
|
|
|
|
|
try:
|
|
|
|
|
with open(tmp, 'wb') as fl:
|
|
|
|
|
fl.write(text)
|
|
|
|
|
if os.path.exists(self._path+'.bak'):
|
|
|
|
|
os.remove(self._path+'.bak')
|
|
|
|
|
os.rename(self._path, self._path+'.bak')
|
|
|
|
|
os.rename(tmp, self._path)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
LOG.warn(f'Error saving to {self._path} ' +str(e))
|
|
|
|
@ -221,17 +230,17 @@ class Settings(dict):
|
|
|
|
|
if os.path.isfile(path):
|
|
|
|
|
os.remove(path)
|
|
|
|
|
|
|
|
|
|
def set_active_profile(self):
|
|
|
|
|
def set_active_profile(self, profile_path):
|
|
|
|
|
"""
|
|
|
|
|
Mark current profile as active
|
|
|
|
|
"""
|
|
|
|
|
path = self._profile_path + '.lock'
|
|
|
|
|
path = profile_path + '.lock'
|
|
|
|
|
try:
|
|
|
|
|
import shutil
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
shutil.copy2(self._profile_path, path)
|
|
|
|
|
shutil.copy2(profile_path, path)
|
|
|
|
|
# need to open this with the same perms as _profile_path
|
|
|
|
|
# copy profile_path and then write?
|
|
|
|
|
with open(path, 'wb') as fl:
|
|
|
|
@ -250,9 +259,9 @@ class Settings(dict):
|
|
|
|
|
# Static methods
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_auto_profile():
|
|
|
|
|
def get_auto_profile(appdir):
|
|
|
|
|
# self._path =
|
|
|
|
|
p = os.path.join(os.path.dirname(self._app._path), 'toxygen.json')
|
|
|
|
|
p = os.path.join(appdir, 'toxygen.json')
|
|
|
|
|
if not os.path.isfile(p):
|
|
|
|
|
return None
|
|
|
|
|
with open(p) as fl:
|
|
|
|
@ -260,14 +269,15 @@ class Settings(dict):
|
|
|
|
|
try:
|
|
|
|
|
auto = json.loads(data)
|
|
|
|
|
except Exception as ex:
|
|
|
|
|
LOG.warn(f"json.loads {data}: {ex!s}")
|
|
|
|
|
LOG.warn(f"json.loads {data}: {ex}")
|
|
|
|
|
auto = {}
|
|
|
|
|
if 'profile_path' in auto:
|
|
|
|
|
path = str(auto['profile_path'])
|
|
|
|
|
if not os.path.isabs(path):
|
|
|
|
|
path = join_path(path, curr_directory(__file__))
|
|
|
|
|
path = join_path(path, os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
|
if os.path.isfile(path):
|
|
|
|
|
return path
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def supported_languages():
|
|
|
|
@ -276,7 +286,7 @@ class Settings(dict):
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def set_auto_profile(path):
|
|
|
|
|
p = os.path.join(os.path.dirname(self._app._path), 'toxygen.json')
|
|
|
|
|
p = os.path.join(os.path.dirname(path), 'toxygen.json')
|
|
|
|
|
if os.path.isfile(p):
|
|
|
|
|
with open(p) as fl:
|
|
|
|
|
data = fl.read()
|
|
|
|
@ -289,7 +299,7 @@ class Settings(dict):
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def reset_auto_profile():
|
|
|
|
|
p = os.path.join(os.path.dirname(self._app._path), 'toxygen.json')
|
|
|
|
|
p = os.path.join(os.path.dirname(app._path), 'toxygen.json')
|
|
|
|
|
if os.path.isfile(p):
|
|
|
|
|
with open(p) as fl:
|
|
|
|
|
data = fl.read()
|
|
|
|
|