Update plugins2settings_manager.py

This commit is contained in:
HibiKier 2022-06-20 22:31:57 +08:00 committed by GitHub
parent 98374dcd74
commit a9a636c9ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,8 +2,10 @@ from typing import List, Optional, Union, Tuple
from .data_class import StaticData
from pathlib import Path
from ruamel.yaml import YAML
from ruamel import yaml
yaml = YAML(typ="safe")
_yaml = YAML(typ="safe")
class Plugins2settingsManager(StaticData):
@ -16,7 +18,7 @@ class Plugins2settingsManager(StaticData):
super().__init__(None)
if file.exists():
with open(file, "r", encoding="utf8") as f:
self._data = yaml.load(f)
self._data = _yaml.load(f)
if self._data:
if "PluginSettings" in self._data.keys():
self._data = (
@ -91,11 +93,19 @@ class Plugins2settingsManager(StaticData):
return key
return keys
def save(self, path: Union[str, Path] = None):
path = path or self.file
if isinstance(path, str):
path = Path(path)
if path:
with open(path, "w", encoding="utf8") as f:
yaml.dump({"PluginSettings": self._data}, f, indent=2, Dumper=yaml.RoundTripDumper, allow_unicode=True)
def reload(self):
"""
重载本地数据
"""
if self.file.exists():
with open(self.file, "r", encoding="utf8") as f:
self._data: dict = yaml.load(f)
self._data: dict = _yaml.load(f)
self._data = self._data["PluginSettings"]