forked from bookfere/Ebook-Translator-Calibre-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
40 lines (29 loc) · 904 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from calibre.utils.config import JSONConfig
preferences = JSONConfig('plugins/ebook_translator')
def init_config(items):
if not preferences:
save_config(items)
def save_config(items):
for key, value in items:
set_config(key, value)
def get_config(key, default=None):
temp = preferences.copy()
for key in key.split('.'):
if isinstance(temp, dict) and key in temp:
temp = temp[key]
continue
temp = None
return temp if temp is not None else default
def set_config(key, value):
temp = preferences
keys = key.split('.')
while len(keys) > 0:
key = keys.pop(0)
if len(keys) > 0:
if key in temp and isinstance(temp[key], dict):
temp = temp[key]
continue
temp[key] = {}
temp = temp[key]
continue
temp[key] = value