-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
48 lines (38 loc) · 1.22 KB
/
settings.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
47
48
import json
import os
PACKED=0
if PACKED:
config_path=f'{os.environ["USERPROFILE"]}\\meatpi_settings.json'
else:
config_path='settings.json'
class Settings(object):
@classmethod
def load_settings(cls: type) -> None:
with open(config_path, 'r') as fp:
cls.settings=json.load(fp)
if not isinstance(cls.settings,dict) or cls.settings.get('version',0)<1:
raise FileNotFoundError
@classmethod
def store_settings(cls: type) -> None:
with open(config_path, 'w') as fp:
json.dump(cls.settings, fp)
@classmethod
def init_settings(cls: type) -> None:
try:
cls.load_settings()
except FileNotFoundError:
cls.settings = cls.ask_settings()
cls.store_settings()
name = {
'auto_restart':'报错重启',
'delay':'功能时差',
'username':'用户名'
}
@staticmethod
def ask_settings() -> dict:
return {
'auto_restart':int(input('是否启用报错自动重启?')),
'delay':float(input('请输入功能时差:')),
'username':input('请输入用户名:'),
'version':1
}