1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-23 00:03:33 +00:00
bazarr/custom_libs/subzero/prefs.py

41 lines
1.2 KiB
Python
Raw Normal View History

2018-10-31 16:08:29 +00:00
# coding=utf-8
2019-09-17 02:04:27 +00:00
from __future__ import absolute_import
2018-10-31 16:08:29 +00:00
import traceback
2019-09-17 02:04:27 +00:00
from .constants import PLUGIN_IDENTIFIER
2018-10-31 16:08:29 +00:00
def get_user_prefs(Prefs, Logger):
"""
loads all user prefs regardless of whether they exist in DefaultPrefs or not
:param Prefs:
:param Logger:
:return:
"""
try:
prefs_set = Prefs._sandbox.preferences._sets[PLUGIN_IDENTIFIER]
except:
Logger.Error("Loading user prefs failed: %s", traceback.format_exc())
return {}
user_prefs = {}
try:
xml_path = prefs_set._user_file_path
if not Prefs._core.storage.file_exists(xml_path):
return {}
prefs_str = Prefs._core.storage.load(xml_path, mtime_key=prefs_set)
prefs_xml = Prefs._core.data.xml.from_string(prefs_str)
for el in prefs_xml:
user_prefs[str(el.tag)] = str(el.text)
except:
Logger.Error("Loading user prefs failed: %s", traceback.format_exc())
else:
return user_prefs
return {}
def update_user_prefs(update_prefs, Prefs, Logger):
prefs_set = Prefs._sandbox.preferences._sets[PLUGIN_IDENTIFIER]
prefs_set.update_user_values(**update_prefs)
Logger.Info("User prefs updated")