From 0fb421412e6887db105c2e0423f4da4c2fe9aa92 Mon Sep 17 00:00:00 2001 From: david-ajax Date: Sun, 21 Dec 2025 23:06:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9A=82=E6=97=B6=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E5=AE=9E=E9=AA=8C=E6=80=A7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/heurams/default/config/config.toml | 8 ++++---- src/heurams/interface/__init__.py | 2 +- src/heurams/interface/screens/dashboard.py | 3 ++- src/heurams/interface/screens/nucreator.py | 3 ++- src/heurams/interface/screens/synctool.py | 2 +- src/heurams/kernel/algorithms/sm15m.py | 13 +++---------- src/heurams/services/vfs.py | 10 +++++++--- tests/interface/test_synctool.py | 11 ++++------- 8 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/heurams/default/config/config.toml b/src/heurams/default/config/config.toml index b0bedc1..c7a3805 100644 --- a/src/heurams/default/config/config.toml +++ b/src/heurams/default/config/config.toml @@ -42,6 +42,7 @@ template_dir = "./data/template" audio = "playsound" # 可选项: playsound(通用), termux(仅用于支持 Android Termux), mpg123(TODO) tts = "edgetts" # 可选项: edgetts llm = "openai" # 可选项: openai +sync = "webdav" # 可选项: 留空, webdav [providers.tts.edgetts] # EdgeTTS 设置 voice = "zh-CN-XiaoxiaoNeural" # 可选项: zh-CN-YunjianNeural (男声), zh-CN-XiaoxiaoNeural (女声) @@ -50,12 +51,11 @@ voice = "zh-CN-XiaoxiaoNeural" # 可选项: zh-CN-YunjianNeural (男声), zh-CN- url = "" key = "" -[sync.webdav] # WebDAV 同步设置 -enabled = false +[providers.sync.webdav] # WebDAV 同步设置 url = "" username = "" password = "" remote_path = "/heurams/" -sync_mode = "bidirectional" # bidirectional/upload_only/download_only -conflict_strategy = "newer" # newer/ask/keep_both verify_ssl = true + +[sync] diff --git a/src/heurams/interface/__init__.py b/src/heurams/interface/__init__.py index 4071b04..8205e2e 100644 --- a/src/heurams/interface/__init__.py +++ b/src/heurams/interface/__init__.py @@ -40,7 +40,7 @@ class HeurAMSApp(App): ("1", "app.push_screen('dashboard')", "仪表盘"), ("2", "app.push_screen('precache_all')", "缓存管理器"), ("3", "app.push_screen('nucleon_creator')", "创建新单元"), - ("4", "app.push_screen('synctool')", "同步工具"), + # ("4", "app.push_screen('synctool')", "同步工具"), ("0", "app.push_screen('about')", "版本信息"), ] SCREENS = { diff --git a/src/heurams/interface/screens/dashboard.py b/src/heurams/interface/screens/dashboard.py index ed09e22..1a323f4 100644 --- a/src/heurams/interface/screens/dashboard.py +++ b/src/heurams/interface/screens/dashboard.py @@ -4,7 +4,8 @@ import pathlib from textual.app import ComposeResult from textual.containers import ScrollableContainer from textual.screen import Screen -from textual.widgets import Button, Footer, Header, Label, ListItem, ListView, Static +from textual.widgets import (Button, Footer, Header, Label, ListItem, ListView, + Static) import heurams.services.timer as timer import heurams.services.version as version diff --git a/src/heurams/interface/screens/nucreator.py b/src/heurams/interface/screens/nucreator.py index b187528..735dda6 100644 --- a/src/heurams/interface/screens/nucreator.py +++ b/src/heurams/interface/screens/nucreator.py @@ -5,7 +5,8 @@ import toml from textual.app import ComposeResult from textual.containers import ScrollableContainer from textual.screen import Screen -from textual.widgets import Button, Footer, Header, Input, Label, Markdown, Select +from textual.widgets import (Button, Footer, Header, Input, Label, Markdown, + Select) from heurams.context import config_var from heurams.services.version import ver diff --git a/src/heurams/interface/screens/synctool.py b/src/heurams/interface/screens/synctool.py index a169ea4..3d1eebe 100644 --- a/src/heurams/interface/screens/synctool.py +++ b/src/heurams/interface/screens/synctool.py @@ -65,7 +65,7 @@ class SyncScreen(Screen): def update_ui_from_config(self): """更新 UI 显示配置信息""" try: - sync_cfg: dict = config_var.get()['providers']['sync']['webdav'] + sync_cfg: dict = config_var.get()["providers"]["sync"]["webdav"] # 更新服务器 URL url = sync_cfg.get("url", "未配置") url_widget = self.query_one("#server_url") diff --git a/src/heurams/kernel/algorithms/sm15m.py b/src/heurams/kernel/algorithms/sm15m.py index 1decbb5..fc5abd7 100644 --- a/src/heurams/kernel/algorithms/sm15m.py +++ b/src/heurams/kernel/algorithms/sm15m.py @@ -14,16 +14,9 @@ import pathlib from typing import TypedDict from heurams.context import config_var -from heurams.kernel.algorithms.sm15m_calc import ( - MAX_AF, - MIN_AF, - NOTCH_AF, - RANGE_AF, - RANGE_REPETITION, - SM, - THRESHOLD_RECALL, - Item, -) +from heurams.kernel.algorithms.sm15m_calc import (MAX_AF, MIN_AF, NOTCH_AF, + RANGE_AF, RANGE_REPETITION, + SM, THRESHOLD_RECALL, Item) # 全局状态文件路径 _GLOBAL_STATE_FILE = os.path.expanduser( diff --git a/src/heurams/services/vfs.py b/src/heurams/services/vfs.py index a7f0988..a024ef8 100644 --- a/src/heurams/services/vfs.py +++ b/src/heurams/services/vfs.py @@ -1,16 +1,20 @@ -""" vfs.py +"""vfs.py 得益于 FSSpec, 无需实现大部分虚拟文件系统的 Providers """ from pathlib import Path + import fsspec as fs -class VFSObject(): + +class VFSObject: def __init__(self, protocol, base_url): self.base_url = base_url self.protocol = protocol - self.fs = fs.filesystem(protocol=protocol, base_url = base_url) + self.fs = fs.filesystem(protocol=protocol, base_url=base_url) + def open(self, path: Path): return self.fs.open(path) + def open_by_list(self, path_list: list[Path]): return self.fs.open_files(path_list) diff --git a/tests/interface/test_synctool.py b/tests/interface/test_synctool.py index 096ac8a..b70d8a3 100644 --- a/tests/interface/test_synctool.py +++ b/tests/interface/test_synctool.py @@ -10,12 +10,8 @@ from unittest.mock import MagicMock, Mock, patch from heurams.context import ConfigContext from heurams.services.config import ConfigFile -from heurams.services.sync_service import ( - ConflictStrategy, - SyncConfig, - SyncMode, - SyncService, -) +from heurams.services.sync_service import (ConflictStrategy, SyncConfig, + SyncMode, SyncService) class TestSyncServiceUnit(unittest.TestCase): @@ -206,7 +202,8 @@ class TestSyncServiceUnit(unittest.TestCase): mock_config.data = config_data mock_config_var.get.return_value = mock_config - from heurams.services.sync_service import create_sync_service_from_config + from heurams.services.sync_service import \ + create_sync_service_from_config service = create_sync_service_from_config()