refactor: streamline file operations and enhance atomic read/write functions

This commit is contained in:
2026-07-06 22:40:51 +08:00
parent ba4e63c401
commit 576e73b5dc
3 changed files with 415 additions and 173 deletions
+3 -3
View File
@@ -7,7 +7,7 @@ from datetime import datetime, timedelta, timezone
import yaml
import module.config.server as server_
from deploy.Windows.atomic import atomic_read, atomic_write
from deploy.Windows.atomic import atomic_read_bytes, atomic_read_text, atomic_write
LANGUAGES = ['zh-CN', 'en-US']
SERVER_TO_TIMEZONE = {
@@ -68,12 +68,12 @@ def read_file(file):
"""
print(f'read: {file}')
if file.endswith('.json'):
content = atomic_read(file, mode='rb')
content = atomic_read_bytes(file)
if not content:
return {}
return json.loads(content)
elif file.endswith('.yaml'):
content = atomic_read(file, mode='r')
content = atomic_read_text(file)
data = list(yaml.safe_load_all(content))
if len(data) == 1:
data = data[0]