chore: Remove obsolete scripts and enhance path configuration

- Deleted `check_md_files.py` and `fix_cursor_md_issue.py` as they are no longer needed.
- Added new functions in `path_config.py` for better path management, including actions log and run_cli paths.
- Updated various modules to utilize the new path configuration, ensuring consistency and maintainability across the project.
This commit is contained in:
Your Name committed 2025-12-28 20:55:34 +08:00
1 parent b9849b9f5a
commit bdf9312bc9
58 files changed
+2472 -854

No files matched your search

+5
View File
@@ -6,3 +6,8 @@
+2 -2
View File
@@ -47,8 +47,8 @@ def create_actions_log_viewer(
path = path_config.get_actions_log_path()
except Exception:
# 回退到旧路径(向后兼容)
path = os.path.join(os.path.dirname(__file__), "..", "logs", "actions.log")
path = os.path.abspath(path)
import path_config
path = path_config.get_actions_log_path()
try:
if os.path.exists(path):
+5
View File
@@ -46,3 +46,8 @@ def save_ui_to_config(
+5
View File
@@ -56,3 +56,8 @@ def create_device_selector(
+5
View File
@@ -42,3 +42,8 @@ def create_image_viewer(
+5
View File
@@ -38,3 +38,8 @@ def create_main_window(
+5
View File
@@ -39,3 +39,8 @@ def create_ocr_panel(
+46 -10
View File
@@ -8,6 +8,12 @@ import warnings
from datetime import datetime
from typing import Any, Callable
# 确保项目根目录在 Python 路径中(支持直接运行 gui/gui_app.py)
_script_dir = os.path.dirname(os.path.abspath(__file__))
_project_root = os.path.dirname(_script_dir)
if _project_root not in sys.path:
sys.path.insert(0, _project_root)
from PIL import Image, ImageTk
# 抽离:ADB/配置/参数结构体到 gui_core.py(便于后续模块化)
@@ -1570,9 +1576,9 @@ def main():
# OCR区域配置:定义所有需要识别的区域(坐标基于1080x2400基准)
OCR_REGIONS = [
# (区域名称, (x1, y1, x2, y2), 描述)
("福袋内容", (390, 1240, 980, 1470), "福袋内容详情"),
("福袋内容", (389, 1273, 1000, 1534), "福袋内容详情"),
("福袋倒计时", (390, 1470, 980, 1580), "福袋倒计时"),
("福袋价值", (390, 1460, 1000, 1580), "奖品价值/价格"),
("福袋价值", (390, 1440, 1000, 1580), "奖品价值/价格"),
("抽奖结果", (380, 660, 720, 755), "抽奖结果弹窗"),
("推荐页标签栏", (400, 140, 900, 200), "推荐/关注/直播标签"),
("推荐页标签栏快速检测", (400, 140, 900, 200), "推荐页快速检测"),
@@ -1620,9 +1626,13 @@ def main():
root.after(0, log_msg("[截图] 截图成功,已保存到 pic/screenshot.png")) # type: ignore[arg-type]
# 读取截图以获取实际尺寸
screenshot_path = os.path.join(
os.path.dirname(__file__), "pic", "screenshot.png"
)
try:
from path_config import get_screenshot_path
screenshot_path = get_screenshot_path()
except Exception:
# 回退到旧路径(向后兼容)
import path_config
screenshot_path = path_config.get_screenshot_path()
if not os.path.exists(screenshot_path):
root.after(0, log_msg("[OCR] 截图文件不存在")) # type: ignore[arg-type]
return
@@ -1886,7 +1896,13 @@ def main():
preview_top = ttk.Frame(preview_tab)
preview_top.pack(fill=X, padx=10, pady=10)
images_dir = os.path.join(os.path.dirname(__file__), "pic")
try:
from path_config import get_pic_dir
images_dir = get_pic_dir()
except Exception:
# 回退到旧路径(向后兼容)
import path_config
images_dir = path_config.get_pic_dir()
def scan_image_files():
"""扫描pic文件夹及其子文件夹中的所有图片文件"""
@@ -2905,7 +2921,13 @@ def main():
pass
def refresh_reservations():
path = os.path.join(os.path.dirname(__file__), "state", "reservations.json")
try:
from path_config import get_reservations_path
path = get_reservations_path()
except Exception:
# 回退到旧路径(向后兼容)
import path_config
path = path_config.get_reservations_path()
try:
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as f:
@@ -3133,7 +3155,13 @@ def main():
pass
def refresh_high_value_rooms():
path = os.path.join(os.path.dirname(__file__), "state", "high_value_rooms.json")
try:
from path_config import get_high_value_rooms_path
path = get_high_value_rooms_path()
except Exception:
# 回退到旧路径(向后兼容)
import path_config
path = path_config.get_high_value_rooms_path()
try:
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as f:
@@ -3173,7 +3201,9 @@ def main():
path = get_actions_log_path()
except Exception:
# 回退到旧路径(向后兼容)
path = os.path.join(os.path.dirname(__file__), "logs", "actions.log")
# 修正路径:GUI应该读取根目录的logs/actions.log
import path_config
path = path_config.get_actions_log_path()
try:
if os.path.exists(path):
# 仿照 web_gui 的实现:只读最后一小段,避免文件巨大
@@ -3405,8 +3435,14 @@ def main():
def auto_refresh_actions_log() -> None:
refresh_actions_log()
root.after(2000, auto_refresh_actions_log) # type: ignore[arg-type]
# 定期刷新预约队列(每5秒)
def auto_refresh_reservations() -> None:
refresh_reservations()
root.after(5000, auto_refresh_reservations) # type: ignore[arg-type]
root.after(2000, auto_refresh_actions_log) # type: ignore[arg-type]
root.after(5000, auto_refresh_reservations) # type: ignore[arg-type]
# 定期刷新统计信息(每3秒)
def auto_refresh_stats() -> None:
+29 -7
View File
@@ -10,8 +10,9 @@ import time
from dataclasses import dataclass
from typing import Optional
import path_config
CONFIG_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "config", "config.json")
CONFIG_PATH = path_config.get_config_path()
def find_adb_executable() -> str:
@@ -717,9 +718,16 @@ class Runner:
# 如果 wait_minutes=0,表示无限循环模式
wait_minutes_arg = str(params.wait_minutes) if params.wait_minutes > 0 else "0"
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"未找到 run_cli.py 文件。\n"
f"预期路径: {run_cli_path}\n"
f"请确保 run_cli.py 位于项目根目录。"
)
cmd = [
sys.executable,
os.path.join(os.path.dirname(__file__), "run_cli.py"),
run_cli_path,
"--y-pianyi",
str(params.y_pianyi),
"--wait-minutes",
@@ -808,7 +816,7 @@ class Runner:
encoding="utf-8",
errors="replace",
env=env,
cwd=os.path.dirname(__file__),
cwd=path_config.PROJECT_ROOT,
)
with self._lock:
@@ -857,9 +865,16 @@ class Runner:
if seconds <= 0:
seconds = 90
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"未找到 run_cli.py 文件。\n"
f"预期路径: {run_cli_path}\n"
f"请确保 run_cli.py 位于项目根目录。"
)
cmd = [
sys.executable,
os.path.join(os.path.dirname(__file__), "run_cli.py"),
run_cli_path,
"--test-yanghao-flow",
"--test-yanghao-flow-seconds",
str(seconds),
@@ -886,7 +901,7 @@ class Runner:
encoding="utf-8",
errors="replace",
env=env,
cwd=os.path.dirname(__file__),
cwd=path_config.PROJECT_ROOT,
)
with self._lock:
@@ -932,9 +947,16 @@ class Runner:
raise RuntimeError("已经在运行")
text = str(text or "").strip()
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"未找到 run_cli.py 文件。\n"
f"预期路径: {run_cli_path}\n"
f"请确保 run_cli.py 位于项目根目录。"
)
cmd = [
sys.executable,
os.path.join(os.path.dirname(__file__), "run_cli.py"),
run_cli_path,
"--test-comment",
]
if text:
@@ -961,7 +983,7 @@ class Runner:
encoding="utf-8",
errors="replace",
env=env,
cwd=os.path.dirname(__file__),
cwd=path_config.PROJECT_ROOT,
)
with self._lock:
+5
View File
@@ -6,3 +6,8 @@
+5
View File
@@ -14,3 +14,8 @@ __all__ = ["ProcRunner"]
+43 -15
View File
@@ -11,9 +11,11 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from typing import Optional
from urllib.parse import parse_qs, urlparse
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CONFIG_PATH = os.path.join(BASE_DIR, "config", "config.json")
WEBUI_DIR = os.path.join(BASE_DIR, "webui")
import path_config
BASE_DIR = path_config.PROJECT_ROOT
CONFIG_PATH = path_config.get_config_path()
WEBUI_DIR = path_config.get_webui_dir()
# ANSI转义序列清理正则表达式
_ANSI_ESCAPE_RE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
@@ -85,7 +87,7 @@ class ProcRunner:
10000 # 0=不限制(可能占用大量内存),增加到10000避免日志被过早截断
)
self._log_file_enabled: bool = True
self._log_file_path: str = os.path.join(BASE_DIR, "logs", "unified.log")
self._log_file_path: str = path_config.get_log_file_path()
self._start_ts: Optional[float] = None
self._last_log_ts: Optional[float] = None
self._exit_code: Optional[int] = None
@@ -124,7 +126,7 @@ class ProcRunner:
path = str(cfg.get("log_unified_path") or "logs/unified.log")
if not os.path.isabs(path):
path = os.path.join(BASE_DIR, path)
path = os.path.join(path_config.PROJECT_ROOT, path)
self._log_file_path = path
try:
@@ -822,8 +824,13 @@ class ProcRunner:
return self._proc is not None and self._proc.poll() is None
def get_reservations(self) -> dict:
"""获取当前预约队列信息(来自子进程写入的 state/reservations.json)。"""
path = os.path.join(BASE_DIR, "state", "reservations.json")
"""获取当前预约队列信息(来自子进程写入的 douyin/core/state/reservations.json)。"""
try:
import path_config
path = path_config.get_reservations_path()
except Exception:
# 回退到旧路径(向后兼容)
path = path_config.get_reservations_path()
try:
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as f:
@@ -846,7 +853,7 @@ class ProcRunner:
def get_high_value_rooms(self) -> dict:
"""获取永久记录的高价值直播间列表(来自 state/high_value_rooms.json)。"""
path = os.path.join(BASE_DIR, "state", "high_value_rooms.json")
path = path_config.get_high_value_rooms_path()
try:
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as f:
@@ -1080,9 +1087,16 @@ class ProcRunner:
if seconds <= 0:
seconds = 60
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"run_cli.py not found.\n"
f"Expected path: {run_cli_path}\n"
f"Please ensure run_cli.py is in the project root directory."
)
cmd = [
sys.executable,
os.path.join(BASE_DIR, "run_cli.py"),
run_cli_path,
"--test-yanghao-flow",
"--test-yanghao-flow-seconds",
str(seconds),
@@ -1097,9 +1111,16 @@ class ProcRunner:
raise RuntimeError("already running")
text = str(text or "").strip()
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"run_cli.py not found.\n"
f"Expected path: {run_cli_path}\n"
f"Please ensure run_cli.py is in the project root directory."
)
cmd = [
sys.executable,
os.path.join(BASE_DIR, "run_cli.py"),
run_cli_path,
"--test-comment",
]
if text:
@@ -1169,9 +1190,16 @@ class ProcRunner:
str(_pick("fansclub_fail_action", "") or "").strip().lower()
)
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"run_cli.py not found.\n"
f"Expected path: {run_cli_path}\n"
f"Please ensure run_cli.py is in the project root directory."
)
cmd = [
sys.executable,
os.path.join(BASE_DIR, "run_cli.py"),
run_cli_path,
"--y-pianyi",
str(y_pianyi),
"--wait-minutes",
@@ -1295,7 +1323,7 @@ class ProcRunner:
encoding="utf-8",
errors="replace",
env=env,
cwd=BASE_DIR,
cwd=path_config.PROJECT_ROOT,
bufsize=1, # 行缓冲模式,确保实时输出
)
@@ -1524,7 +1552,7 @@ class Handler(BaseHTTPRequestHandler):
path = (
RUNNER._log_file_path
if hasattr(RUNNER, "_log_file_path")
else os.path.join(BASE_DIR, "logs", "unified.log")
else path_config.get_log_file_path()
)
out_lines = []
try:
@@ -1555,7 +1583,7 @@ class Handler(BaseHTTPRequestHandler):
path = path_config.get_actions_log_path()
except Exception:
# 回退到旧路径(向后兼容)
path = os.path.join(BASE_DIR, "logs", "actions.log")
path = path_config.get_actions_log_path()
out_lines: list[str] = []
try:
if os.path.exists(path):
@@ -1580,7 +1608,7 @@ class Handler(BaseHTTPRequestHandler):
if not safe.startswith("pic/"):
self.send_error(HTTPStatus.FORBIDDEN)
return
full = os.path.join(BASE_DIR, safe)
full = os.path.join(path_config.PROJECT_ROOT, safe)
if not os.path.isfile(full):
self.send_error(HTTPStatus.NOT_FOUND)
return