更换yaml库
This commit is contained in:
parent
145488e067
commit
0e784e4e6e
10
config.py
10
config.py
@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import yaml
|
||||||
from loghelper import log
|
from loghelper import log
|
||||||
from ruamel.yaml import YAML
|
|
||||||
|
|
||||||
# 这个字段现在还没找好塞什么地方好,就先塞config这里了
|
# 这个字段现在还没找好塞什么地方好,就先塞config这里了
|
||||||
serverless = False
|
serverless = False
|
||||||
@ -87,16 +87,14 @@ def update_config():
|
|||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
yaml = YAML()
|
|
||||||
global config
|
global config
|
||||||
with open(config_Path, "r", encoding='utf-8') as f:
|
with open(config_Path, "r", encoding='utf-8') as f:
|
||||||
config = yaml.load(f)
|
config = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
log.info("Config加载完毕")
|
log.info("Config加载完毕")
|
||||||
|
|
||||||
|
|
||||||
def save_config():
|
def save_config():
|
||||||
global serverless
|
global serverless
|
||||||
yaml = YAML()
|
|
||||||
if serverless:
|
if serverless:
|
||||||
log.info("云函数执行,无法保存")
|
log.info("云函数执行,无法保存")
|
||||||
return None
|
return None
|
||||||
@ -104,7 +102,7 @@ def save_config():
|
|||||||
try:
|
try:
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
f.truncate()
|
f.truncate()
|
||||||
yaml.dump(config, f)
|
f.write(yaml.dump(config, Dumper=yaml.Dumper,sort_keys=False))
|
||||||
f.flush()
|
f.flush()
|
||||||
except OSError:
|
except OSError:
|
||||||
serverless = True
|
serverless = True
|
||||||
@ -130,7 +128,7 @@ def clear_cookies():
|
|||||||
try:
|
try:
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
f.truncate()
|
f.truncate()
|
||||||
yaml.dump(config, f)
|
f.write(yaml.dump(config, Dumper=yaml.Dumper,sort_keys=False))
|
||||||
f.flush()
|
f.flush()
|
||||||
except OSError:
|
except OSError:
|
||||||
serverless = True
|
serverless = True
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
httpx>=0.21.1
|
httpx>=0.21.1
|
||||||
requests>=2.26.0
|
requests>=2.26.0
|
||||||
crontab~=0.23.0
|
crontab~=0.23.0
|
||||||
ruamel.yaml~=0.17.21
|
PyYAML~=6.0
|
||||||
|
Loading…
Reference in New Issue
Block a user