mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-08 08:57:09 +08:00
Use ruamel.yaml consistently in CategoryHelper
Co-authored-by: jxxghp <51039935+jxxghp@users.noreply.github.com>
This commit is contained in:
co-authored by
jxxghp
parent
27756a53db
commit
5d3443fee4
@@ -1,5 +1,4 @@
|
|||||||
import shutil
|
import shutil
|
||||||
import yaml
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
@@ -69,7 +68,8 @@ class CategoryHelper(metaclass=WeakSingleton):
|
|||||||
return config
|
return config
|
||||||
try:
|
try:
|
||||||
with open(self._category_path, 'r', encoding='utf-8') as f:
|
with open(self._category_path, 'r', encoding='utf-8') as f:
|
||||||
data = yaml.safe_load(f)
|
yaml_loader = ruamel.yaml.YAML()
|
||||||
|
data = yaml_loader.load(f)
|
||||||
if data:
|
if data:
|
||||||
config = CategoryConfig(**data)
|
config = CategoryConfig(**data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -84,7 +84,8 @@ class CategoryHelper(metaclass=WeakSingleton):
|
|||||||
try:
|
try:
|
||||||
with open(self._category_path, 'w', encoding='utf-8') as f:
|
with open(self._category_path, 'w', encoding='utf-8') as f:
|
||||||
f.write(HEADER_COMMENTS)
|
f.write(HEADER_COMMENTS)
|
||||||
yaml.dump(data, f, allow_unicode=True, sort_keys=False, default_flow_style=False)
|
yaml_dumper = ruamel.yaml.YAML()
|
||||||
|
yaml_dumper.dump(data, f)
|
||||||
# 保存后重新加载配置
|
# 保存后重新加载配置
|
||||||
self.init()
|
self.init()
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user