-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersistence.py
46 lines (36 loc) · 1.2 KB
/
persistence.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
41
42
43
44
45
46
import json
import os
import platform
from pathlib import Path
def load():
path = get_appdata_path() / 'settings.json'
default_settings = {
'selected_model': 'none',
'dev': 'false'
}
if os.path.exists(path):
with open(path, 'r') as json_file:
return json.load(json_file)
else:
with open(path, 'w') as json_file:
json.dump(default_settings, json_file, indent=4)
return default_settings
def __save__(settings):
with open(get_appdata_path() / 'settings.json', 'w') as json_file:
json.dump(settings, json_file, indent=4)
def set(settings, key, value):
settings[key] = value
__save__(settings)
def get_appdata_path():
system = platform.system()
if system == "Windows":
return Path(os.path.join(os.environ.get('APPDATA'), 'Moerkepub'))
elif system == "Linux":
return Path.home() / '.config' / 'Moerkepub'
else:
raise ValueError("Unsupported operating system")
def ensure_program_files():
appdata_path = get_appdata_path()
appdata_path.mkdir(parents=False, exist_ok=True)
downloaded = get_appdata_path() / 'models'
downloaded.mkdir(parents=False, exist_ok=True)