小批量收尾:删除零引用 scrcpy_screenshot + douyin_fudai/log_viewer print→logger
- 删除 operations/scrcpy_screenshot.py(100 行,仅自身定义自身使用,全仓零外部引用) - douyin/core/douyin_fudai.py:3 处兜底 print → logging.info/warning(_log_kv 失败时的兜底路径) - gui/components/log_viewer.py:2 处错误 print → _LOGVIEW_LOGGER.exception(日志线程异常 / 刷新显示异常) 回归:149→148 .py,全量编译通过;test_filter_logging / check_web_gui_config_sync 通过; fudai_analyse 类正常导出,log_viewer 模块加载 OK。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
938011f672
commit
96f8600d42
3 files changed
+9
-105
No files matched your search
@@ -454,7 +454,7 @@ class fudai_analyse:
|
||||
"养号", "_yanghao_recommend_flow skipped - yanghao_enabled=0"
|
||||
)
|
||||
except Exception:
|
||||
print("[养号] _yanghao_recommend_flow skipped - yanghao_enabled=0")
|
||||
logging.info("[养号] _yanghao_recommend_flow skipped - yanghao_enabled=0")
|
||||
return
|
||||
from douyin.other import douyin_yanghao
|
||||
|
||||
@@ -595,7 +595,7 @@ class fudai_analyse:
|
||||
wait_minutes=wait_minutes,
|
||||
)
|
||||
except Exception:
|
||||
print(
|
||||
logging.warning(
|
||||
f"[DEBUG] entered fudai_choujiang device_id={device_id} wait_minutes={wait_minutes}"
|
||||
)
|
||||
self.device_id = device_id or self.device_id
|
||||
@@ -625,7 +625,7 @@ class fudai_analyse:
|
||||
error=str(e),
|
||||
)
|
||||
except Exception:
|
||||
print(
|
||||
logging.warning(
|
||||
f"[DEBUG] get_device_resolution attempt {attempt+1} failed: {e}"
|
||||
)
|
||||
time.sleep(1.0)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable, Optional, List, Dict, Tuple
|
||||
import logging
|
||||
import queue
|
||||
import re
|
||||
import threading
|
||||
@@ -16,6 +17,9 @@ import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from tkinter.scrolledtext import ScrolledText
|
||||
|
||||
# 模块级 logger:内部错误(日志线程异常 / 刷新显示异常)走 logging,避免裸 print
|
||||
_LOGVIEW_LOGGER = logging.getLogger("gui.components.log_viewer")
|
||||
|
||||
try:
|
||||
from ttkbootstrap.scrolled import ScrolledText as TBSrolledText
|
||||
ScrolledText = TBSrolledText
|
||||
@@ -230,7 +234,7 @@ class EnhancedLogViewer(ttk.Frame):
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
print(f"日志处理错误: {e}")
|
||||
_LOGVIEW_LOGGER.exception("日志处理错误: %s", e)
|
||||
|
||||
time.sleep(0.1) # 避免CPU占用过高
|
||||
|
||||
@@ -343,7 +347,7 @@ class EnhancedLogViewer(ttk.Frame):
|
||||
self.log_text.see("end")
|
||||
|
||||
except Exception as e:
|
||||
print(f"刷新显示错误: {e}")
|
||||
_LOGVIEW_LOGGER.exception("刷新显示错误: %s", e)
|
||||
|
||||
def _insert_colored_line(self, line: str) -> None:
|
||||
"""插入带颜色的日志行"""
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
"""使用 scrcpy server 模式进行截图(高性能替代方案)
|
||||
|
||||
scrcpy 通过 server 模式可以实现比 adb screencap 更快的截图速度。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
import tempfile
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
from operations.screenshot_operations import ScreenshotOperations
|
||||
|
||||
|
||||
class ScrcpyScreenshot:
|
||||
"""使用 scrcpy server 进行截图"""
|
||||
|
||||
def __init__(self):
|
||||
self._scrcpy_path: Optional[str] = None
|
||||
self._server_path: Optional[str] = None
|
||||
self._find_scrcpy()
|
||||
|
||||
def _find_scrcpy(self):
|
||||
"""查找 scrcpy 可执行文件"""
|
||||
import shutil
|
||||
|
||||
# 先检查 PATH
|
||||
which_path = shutil.which('scrcpy')
|
||||
if which_path:
|
||||
self._scrcpy_path = which_path
|
||||
return
|
||||
|
||||
# 检查常见安装位置
|
||||
candidates = [
|
||||
os.path.join(os.getenv('LOCALAPPDATA', ''), 'Programs', 'scrcpy', 'scrcpy.exe'),
|
||||
os.path.join(os.getenv('USERPROFILE', ''), 'AppData', 'Local', 'Programs', 'scrcpy', 'scrcpy.exe'),
|
||||
r'C:\Program Files\scrcpy\scrcpy.exe',
|
||||
r'C:\Program Files (x86)\scrcpy\scrcpy.exe',
|
||||
]
|
||||
|
||||
for path in candidates:
|
||||
if path and os.path.exists(path):
|
||||
self._scrcpy_path = path
|
||||
# server 文件通常在同一目录
|
||||
server_path = os.path.join(os.path.dirname(path), 'scrcpy-server')
|
||||
if os.path.exists(server_path):
|
||||
self._server_path = server_path
|
||||
break
|
||||
|
||||
def is_available(self) -> bool:
|
||||
"""检查 scrcpy 是否可用"""
|
||||
return self._scrcpy_path is not None and os.path.exists(self._scrcpy_path)
|
||||
|
||||
def get_screenshot(self, device_id: str, output_path: str) -> bool:
|
||||
"""使用 scrcpy 进行截图
|
||||
|
||||
注意:scrcpy 本身不直接支持单次截图,这里使用变通方法:
|
||||
1. 启动 scrcpy server(如果支持)
|
||||
2. 或使用 scrcpy 的录制功能提取帧
|
||||
|
||||
参数:
|
||||
device_id: 设备ID
|
||||
output_path: 输出文件路径
|
||||
|
||||
返回:
|
||||
是否成功
|
||||
"""
|
||||
if not self.is_available():
|
||||
return False
|
||||
|
||||
timetag = datetime.now().strftime("%H:%M:%S")
|
||||
start_time = time.time()
|
||||
|
||||
try:
|
||||
# 方法1: 使用 scrcpy 的 --record 功能(需要停止机制,较复杂)
|
||||
# 方法2: 使用 scrcpy server 模式(推荐,但需要额外配置)
|
||||
# 方法3: 回退到 adb screencap(当前实现)
|
||||
|
||||
# 由于 scrcpy 不直接支持单次截图,这里先记录日志
|
||||
# 实际实现需要集成 scrcpy server 或使用第三方库
|
||||
print(f"[{timetag}] [scrcpy] 注意: scrcpy 不直接支持单次截图")
|
||||
print(f"[{timetag}] [scrcpy] 需要使用 scrcpy server 模式或集成到截图流程")
|
||||
|
||||
# 暂时回退到标准截图方法
|
||||
ops = ScreenshotOperations()
|
||||
return ops._get_screenshot_direct(device_id, os.path.dirname(output_path))
|
||||
|
||||
except Exception as e:
|
||||
elapsed = (time.time() - start_time) * 1000
|
||||
print(f"[{timetag}] [scrcpy] 截图失败: {e},耗时: {elapsed:.0f}ms")
|
||||
return False
|
||||
|
||||
|
||||
def get_scrcpy_screenshot(device_id: str, output_path: str) -> bool:
|
||||
"""获取 scrcpy 截图(便捷函数)"""
|
||||
scrcpy = ScrcpyScreenshot()
|
||||
return scrcpy.get_screenshot(device_id, output_path)
|
||||
Reference in new issue
Block a user