mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Code for exporting a subset of preferences
This commit is contained in:
parent
4cea6a59b5
commit
b288b964c8
@ -79,11 +79,11 @@ all_settings = {
|
||||
'gesture_overrides': {'default': {}, 'category': 'read_book'},
|
||||
}
|
||||
|
||||
|
||||
defaults = {}
|
||||
for x in Object.entries(all_settings):
|
||||
defaults[x[0]] = x[1].default
|
||||
|
||||
|
||||
def session_defaults():
|
||||
return defaults
|
||||
|
||||
@ -127,6 +127,7 @@ def get_session_storage():
|
||||
console.error('sessionStorage and localStorage not available using a temp cache instead')
|
||||
return get_session_storage.ans
|
||||
|
||||
|
||||
class SessionData:
|
||||
|
||||
def __init__(self, global_prefix=None):
|
||||
@ -194,6 +195,45 @@ def get_device_uuid():
|
||||
return get_device_uuid.ans
|
||||
|
||||
|
||||
def deep_eq(a, b):
|
||||
if a is b:
|
||||
return True
|
||||
if Array.isArray(a) and Array.isArray(b):
|
||||
if a.length is not b.length:
|
||||
return False
|
||||
for i in range(a.length):
|
||||
if not deep_eq(a[i], b[i]):
|
||||
return False
|
||||
return True
|
||||
if a is None or b is None or a is undefined or b is undefined:
|
||||
return False
|
||||
if jstype(a) is not 'object' or jstype(b) is not 'object':
|
||||
return False
|
||||
ka = Object.keys(a)
|
||||
if ka.length is not Object.keys(b).length:
|
||||
return False
|
||||
for key in ka:
|
||||
if not deep_eq(a[ka], b[ka]):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def setting_val_is_default(setting_name, curval):
|
||||
defval = defaults[setting_name]
|
||||
return deep_eq(defval, curval)
|
||||
|
||||
|
||||
def get_subset_of_settings(sd, filter_func):
|
||||
ans = {}
|
||||
for setting_name in Object.keys(all_settings):
|
||||
curval = sd.get(setting_name, ans)
|
||||
metadata = all_settings[setting_name]
|
||||
is_set = curval is not ans
|
||||
if filter_func(setting_name, metadata, is_set):
|
||||
ans[setting_name] = curval if is_set else metadata.default
|
||||
return ans
|
||||
|
||||
|
||||
default_interface_data = {
|
||||
'username': None,
|
||||
'output_format': 'EPUB',
|
||||
|
Loading…
x
Reference in New Issue
Block a user