mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
✨ 增强插件商店功能,优化添加插件时的提示信息,明确区分插件模块和名称。新增 Windows 下删除只读文件的处理逻辑,提升插件管理的稳定性和用户体验。
This commit is contained in:
parent
fe5e6101e7
commit
a6031ee091
@ -104,7 +104,9 @@ async def _(session: EventSession, plugin_id: str, source: Match[str]):
|
|||||||
if is_number(plugin_id):
|
if is_number(plugin_id):
|
||||||
await MessageUtils.build_message(f"正在添加插件 Id: {plugin_id}").send()
|
await MessageUtils.build_message(f"正在添加插件 Id: {plugin_id}").send()
|
||||||
else:
|
else:
|
||||||
await MessageUtils.build_message(f"正在添加插件 Module: {plugin_id}").send()
|
await MessageUtils.build_message(
|
||||||
|
f"正在添加插件 Module/名称: {plugin_id}"
|
||||||
|
).send()
|
||||||
source_str = source.result if source.available else None
|
source_str = source.result if source.available else None
|
||||||
if source_str and source_str not in ["ali", "git"]:
|
if source_str and source_str not in ["ali", "git"]:
|
||||||
await MessageUtils.build_message(
|
await MessageUtils.build_message(
|
||||||
|
|||||||
@ -14,7 +14,7 @@ from zhenxun.utils.image_utils import BuildImage, ImageTemplate, RowStyle
|
|||||||
from zhenxun.utils.manager.virtual_env_package_manager import VirtualEnvPackageManager
|
from zhenxun.utils.manager.virtual_env_package_manager import VirtualEnvPackageManager
|
||||||
from zhenxun.utils.repo_utils import RepoFileManager
|
from zhenxun.utils.repo_utils import RepoFileManager
|
||||||
from zhenxun.utils.repo_utils.models import RepoFileInfo, RepoType
|
from zhenxun.utils.repo_utils.models import RepoFileInfo, RepoType
|
||||||
from zhenxun.utils.utils import is_number
|
from zhenxun.utils.utils import is_number, win_on_rm_error
|
||||||
|
|
||||||
from .config import (
|
from .config import (
|
||||||
BASE_PATH,
|
BASE_PATH,
|
||||||
@ -352,7 +352,8 @@ class StoreManager:
|
|||||||
return f"插件 {plugin_info.name} 不存在..."
|
return f"插件 {plugin_info.name} 不存在..."
|
||||||
logger.debug(f"尝试移除插件 {plugin_info.name} 文件: {path}", LOG_COMMAND)
|
logger.debug(f"尝试移除插件 {plugin_info.name} 文件: {path}", LOG_COMMAND)
|
||||||
if plugin_info.is_dir:
|
if plugin_info.is_dir:
|
||||||
shutil.rmtree(path)
|
# 处理 Windows 下 .git 等目录内只读文件导致的 WinError 5
|
||||||
|
shutil.rmtree(path, onerror=win_on_rm_error)
|
||||||
else:
|
else:
|
||||||
path.unlink()
|
path.unlink()
|
||||||
await PluginInitManager.remove(f"zhenxun.{plugin_info.module_path}")
|
await PluginInitManager.remove(f"zhenxun.{plugin_info.module_path}")
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import stat
|
||||||
import time
|
import time
|
||||||
from typing import ClassVar
|
from types import TracebackType
|
||||||
|
from typing import Any, ClassVar
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from nonebot_plugin_uninfo import Uninfo
|
from nonebot_plugin_uninfo import Uninfo
|
||||||
@ -241,3 +244,24 @@ def is_number(text: str) -> bool:
|
|||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def win_on_rm_error(
|
||||||
|
func: Callable[[str], Any],
|
||||||
|
path: str,
|
||||||
|
_exc_info: tuple[type[BaseException], BaseException, TracebackType],
|
||||||
|
) -> None:
|
||||||
|
"""Windows下删除只读文件/目录时的回调。
|
||||||
|
|
||||||
|
去除只读属性后重试删除,避免 WinError 5。
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
os.chmod(path, stat.S_IWRITE)
|
||||||
|
except Exception:
|
||||||
|
# 即使去除权限失败也继续尝试
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
func(path)
|
||||||
|
except Exception:
|
||||||
|
# 仍失败则记录调试日志并忽略,交由上层继续处理
|
||||||
|
logger.debug(f"删除失败重试仍失败: {path}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user