|
|
|
|
# 项目修改记录
|
|
|
|
|
|
|
|
|
|
## 2025-08-07
|
|
|
|
|
|
|
|
|
|
### Python版本兼容性分析
|
|
|
|
|
- 分析了 `requirements.txt` 中的依赖包版本
|
|
|
|
|
- 确定支持的Python版本范围:3.8 - 3.11
|
|
|
|
|
- 推荐使用Python 3.9或3.10版本
|
|
|
|
|
|
|
|
|
|
### pip编码问题修复
|
|
|
|
|
- 修复了 `requirements.txt` 中中文注释导致的GBK编码错误
|
|
|
|
|
- 将中文注释改为英文注释
|
|
|
|
|
- 建议升级pip版本到最新版本
|
|
|
|
|
|
|
|
|
|
### adbutils版本修复
|
|
|
|
|
- 修复了 `adbutils==2.0.0` 版本不存在的问题
|
|
|
|
|
- 更新为 `adbutils==2.10.0`(有效的最新版本)
|
|
|
|
|
|
|
|
|
|
### 配置模块导出修复
|
|
|
|
|
- 修复了 `ProtocolType` 和 `DeviceStatus` 无法从 `app.core.config` 导入的问题
|
|
|
|
|
- 在 `app/core/config/__init__.py` 中添加了这两个类的导入和导出
|
|
|
|
|
|
|
|
|
|
### 设备管理器导入路径修复
|
|
|
|
|
- 修复了多个服务文件中 `device_manager` 导入路径错误的问题
|
|
|
|
|
- 将 `from app.core.device_manager import device_manager` 改为 `from app.core.device.manager import device_manager`
|
|
|
|
|
- 修复了多个API端点文件中的导入路径错误
|
|
|
|
|
|
|
|
|
|
### 服务类名称修复
|
|
|
|
|
- 修复了 `app/core/device/dispatcher.py` 中服务类名称错误的问题
|
|
|
|
|
- 将 `ADBService`、`SSHService`、`ATService`、`PLNKService`、`ATXService` 改为 `AdbService`、`SshService`、`AtService`、`PlnkService`、`AtxService`
|
|
|
|
|
|
|
|
|
|
### 未使用的导入清理
|
|
|
|
|
- 移除了 `app/api/v1/endpoints/adb.py` 中未使用的 `UploadFile` 和 `File` 导入
|
|
|
|
|
- 这解决了 `python-multipart` 依赖问题
|
|
|
|
|
|
|
|
|
|
### 警告过滤添加
|
|
|
|
|
- 在 `run.py` 中添加了 `warnings.filterwarnings` 来忽略paramiko的弃用警告
|
|
|
|
|
- 解决了 TripleDES 加密算法弃用警告
|
|
|
|
|
|
|
|
|
|
### USB监控模块删除
|
|
|
|
|
- 删除了 `app/api/v1/endpoints/usb_monitor.py` 文件
|
|
|
|
|
- 该文件依赖不存在的 `device_monitor_manager` 服务
|
|
|
|
|
- 更新了 `app/core/app/router.py` 和 `app/api/v1/endpoints/__init__.py` 中的相关引用
|
|
|
|
|
- 这解决了路由注册时的导入错误问题
|
|
|
|
|
|
|
|
|
|
### 路由管理器实例调用修复
|
|
|
|
|
- 修复了 `app/core/app/factory.py` 中路由注册失败的问题
|
|
|
|
|
- 将 `RouterManager.register_all_routers(app)` 改为使用全局实例 `router_manager.register_all_routers(app)`
|
|
|
|
|
- 解决了 "路由注册失败" 错误,因为之前错误地调用了类方法而不是实例方法
|
|
|
|
|
|
|
|
|
|
### python-multipart依赖启用
|
|
|
|
|
- 在 `requirements.txt` 中启用了 `python-multipart==0.0.6` 依赖
|
|
|
|
|
- 解决了FastAPI路由注册时提示需要安装python-multipart的错误
|
|
|
|
|
- 虽然代码中没有直接使用表单数据,但FastAPI在某些情况下会自动检测到可能需要处理表单数据
|
|
|
|
|
|
|
|
|
|
### 导入路径修复
|
|
|
|
|
- 修复了 `app/services/enhanced_adb_service.py` 中错误的导入路径
|
|
|
|
|
- 将 `from app.core.adb_client import AdbClient` 改为 `from app.core.adb import AdbClient`
|
|
|
|
|
- 将 `from app.core.adb_exceptions import ...` 改为 `from app.core.exceptions import ...`
|
|
|
|
|
- 修复了 `test_exception_handling.py` 中的多个导入路径错误
|
|
|
|
|
- 解决了 "No module named 'app.core.adb_client'" 的导入错误
|
|
|
|
|
|
|
|
|
|
### AdbClient API适配修复
|
|
|
|
|
- 修复了 `app/services/enhanced_adb_service.py` 中 `AdbClient` 构造函数调用错误
|
|
|
|
|
- 将 `AdbClient(host, port)` 改为 `AdbClient()`,并将host和port保存为实例变量
|
|
|
|
|
- 修复了方法调用不匹配的问题:
|
|
|
|
|
- `get_server_info()` 改为使用 `server_version()`
|
|
|
|
|
- `list_devices()` 改为使用 `devices()`
|
|
|
|
|
- `execute_shell_command()` 改为使用 `shell()`
|
|
|
|
|
- `list_forward_ports()` 改为使用 `forward_list()`
|
|
|
|
|
- 添加了状态字符串到枚举的转换逻辑
|
|
|
|
|
- 解决了 "AdbClient.__init__() takes 1 positional argument but 3 were given" 错误
|
|
|
|
|
|
|
|
|
|
## 2025-08-07 - 修复路由注册失败问题
|
|
|
|
|
|
|
|
|
|
### 问题描述
|
|
|
|
|
应用启动时出现路由注册失败错误:
|
|
|
|
|
```
|
|
|
|
|
{"timestamp": "2025-08-07T16:10:55.327368", "level": "ERROR", "message": "路由注册失败", "logger_name": "app.core.app.router", "context": {"request_id": null, "user_id": null, "session_id": null, "module": "structured_log", "function": "_log", "line_number": 123, "timestamp": "2025-08-07T16:10:55.327368", "duration_ms": null, "extra": {"error": "no running event loop"}}, "exception": null, "stack_trace": null}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 问题原因
|
|
|
|
|
`EnhancedAdbService` 类在构造函数中自动启动了设备监控,调用了 `asyncio.create_task()`,但此时还没有运行的事件循环,导致 "no running event loop" 错误。
|
|
|
|
|
|
|
|
|
|
### 修复方案
|
|
|
|
|
|
|
|
|
|
#### 1. 修改 EnhancedAdbService 类 (`app/services/enhanced_adb_service.py`)
|
|
|
|
|
- 移除构造函数中的自动启动监控逻辑
|
|
|
|
|
- 将 `_start_monitoring()` 方法改为异步的 `start_monitoring()` 方法
|
|
|
|
|
- 添加 `stop_monitoring()` 方法用于停止监控
|
|
|
|
|
- 修改 `_monitor_devices()` 方法,移除自动重启逻辑
|
|
|
|
|
|
|
|
|
|
#### 2. 修改 enhanced_adb 端点 (`app/api/v1/endpoints/enhanced_adb.py`)
|
|
|
|
|
- 将全局 `EnhancedAdbService` 实例改为延迟初始化
|
|
|
|
|
- 添加 `get_adb_service()` 函数实现延迟初始化
|
|
|
|
|
- 更新所有端点函数,在需要时调用 `get_adb_service()` 获取服务实例
|
|
|
|
|
|
|
|
|
|
### 修改的文件
|
|
|
|
|
1. `app/services/enhanced_adb_service.py` - 修复异步初始化问题
|
|
|
|
|
2. `app/api/v1/endpoints/enhanced_adb.py` - 实现延迟初始化
|
|
|
|
|
|
|
|
|
|
### 影响
|
|
|
|
|
- 修复了应用启动时的路由注册失败问题
|
|
|
|
|
- 设备监控功能现在需要手动启动,而不是自动启动
|
|
|
|
|
- 提高了应用的启动稳定性
|
|
|
|
|
|
|
|
|
|
### 后续建议
|
|
|
|
|
- 如果需要自动启动设备监控,可以在应用启动完成后(有事件循环运行时)手动调用 `start_monitoring()`
|
|
|
|
|
- 考虑在应用关闭时调用 `stop_monitoring()` 来清理资源
|