From 13b1f2150c68ea00289aa88f2068d2e036c688bb Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 20 May 2026 19:18:34 +0800 Subject: [PATCH] Fix launcher paths and remove local hardcoding --- .github/copilot-instructions.md | 2 +- README.md | 8 ++++---- Underlying_Operations.py | 18 +++++++--------- docs/完整技术文档.md | 3 +-- docs/真机测试报告.md | 3 +-- docs/设置定时任务说明.md | 13 ++++++------ docs/高价值房间重访功能说明.md | 2 +- douyin/fudai/douyin_fudai_flow.py | 21 +++++++------------ gui/webgui_launcher.py | 7 ++++--- gui_app.py | 32 +++++++++++++++++++++++++++++ run_cli.py | 13 +++--------- scripts/auto_commit_push.bat | 18 ++++++++++------ scripts/auto_commit_push.ps1 | 34 ++++++++++++++++++++++++++++--- scripts/setup_auto_commit.ps1 | 5 ++--- webgui_launcher.py | 32 +++++++++++++++++++++++++++++ 15 files changed, 145 insertions(+), 66 deletions(-) create mode 100644 gui_app.py create mode 100644 webgui_launcher.py diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 0a37379..1d45f1f 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -1,4 +1,4 @@ -# Copilot 指令(douyin_guaji-main) +# Copilot 指令(本仓库) ## 来自 `docs/完整技术文档.md` 的补充(要点) - 版本:V4.5(2026-01-18)。本文件为实现细节与验证命令的权威来源,agent 在执行重大改动前请核对文档中的“验证要点”。 diff --git a/README.md b/README.md index 21c0f91..ffbe361 100644 --- a/README.md +++ b/README.md @@ -373,7 +373,7 @@ pytest tests/unit/test_example.py::test_some_behavior -q ```bash # 如果使用 Git git clone -cd douyin_guaji-main +cd <项目目录> # 或直接下载 ZIP 文件并解压 ``` @@ -872,7 +872,7 @@ python run_cli.py \ 项目采用模块化设计,主要代码位于 `douyin/` 目录下,按功能划分为多个子模块: ``` -douyin_guaji-main/ +<项目目录>/ ├── douyin/ # 核心业务逻辑模块 │ ├── core/ # 核心调度和主流程 │ │ ├── douyin_fudai.py # 主类 fudai_analyse(Mixin 组合) @@ -1235,7 +1235,7 @@ douyin_guaji-main/ 1. **克隆项目** ```bash git clone - cd douyin_guaji-main + cd <项目目录> ``` 2. **创建虚拟环境** @@ -1532,4 +1532,4 @@ douyin_guaji-main/ 如果这个项目对你有帮助,欢迎 Star ⭐ - \ No newline at end of file + diff --git a/Underlying_Operations.py b/Underlying_Operations.py index 01f4240..615473e 100644 --- a/Underlying_Operations.py +++ b/Underlying_Operations.py @@ -38,17 +38,13 @@ try: except Exception: _RESAMPLE = Image -# 外部完整版 fudai 逻辑所在的工作树路径,用于镜像 screenshot 给那边使用 -# 使用环境变量或默认路径,避免硬编码用户路径 -_EXTERNAL_AXF_SCREENSHOT = os.path.join( - os.environ.get( - "EXTERNAL_DOUYIN_FUDAI_DIR", - os.path.join( - os.path.expanduser("~"), ".cursor", "worktrees", "douyin_guaji-main", "axf" - ), - ), - "pic", - "screenshot.png", +# 外部完整版 fudai 逻辑所在的工作树路径,用于镜像 screenshot 给那边使用。 +# 仅在显式设置 EXTERNAL_DOUYIN_FUDAI_DIR 时启用,避免绑定某台机器的旧路径。 +_EXTERNAL_DOUYIN_FUDAI_DIR = os.environ.get("EXTERNAL_DOUYIN_FUDAI_DIR", "").strip() +_EXTERNAL_AXF_SCREENSHOT = ( + os.path.join(_EXTERNAL_DOUYIN_FUDAI_DIR, "pic", "screenshot.png") + if _EXTERNAL_DOUYIN_FUDAI_DIR + else "" ) diff --git a/docs/完整技术文档.md b/docs/完整技术文档.md index 0eb01a9..42c3555 100644 --- a/docs/完整技术文档.md +++ b/docs/完整技术文档.md @@ -7097,7 +7097,7 @@ debug_logger.log_exception(e, context={"step": "处理福袋"}) 示例:快速启用截图镜像并保留调试图像(Linux/WSL 或 PowerShell 环境变量用法相似) ```bash -EXTERNAL_DOUYIN_FUDAI_DIR=/mnt/share/douyin_debug SKIP_OCR_INIT=1 python run_cli.py --device-id --needswitch +EXTERNAL_DOUYIN_FUDAI_DIR=<外部调试目录> SKIP_OCR_INIT=1 python run_cli.py --device-id --needswitch ``` 示例:禁用截图镜像以提高性能 @@ -7361,4 +7361,3 @@ def get_fudai_contain(analyser, renwu: int = 2): - 第24章:OCR预处理和优化详解 - 第25章:路径配置系统详解 - 第26章:文本处理工具函数详解 - diff --git a/docs/真机测试报告.md b/docs/真机测试报告.md index a2e79c3..c1d9175 100644 --- a/docs/真机测试报告.md +++ b/docs/真机测试报告.md @@ -13,7 +13,7 @@ ### ✅ 日志文件写入功能正常 **验证点1: 日志文件存在** -- 文件路径: `C:\Users\12742\Desktop\douyin_guaji-main\logs\unified_2025-12-22.log` +- 文件路径: `logs/unified_2025-12-22.log` - 文件大小: 8800 bytes - 总行数: 126行 @@ -96,4 +96,3 @@ GUI应用的日志写入功能: **测试状态**: ✅ 通过 **功能状态**: ✅ 正常 **建议**: 可以投入使用 - diff --git a/docs/设置定时任务说明.md b/docs/设置定时任务说明.md index 4ef8faf..c501d2e 100644 --- a/docs/设置定时任务说明.md +++ b/docs/设置定时任务说明.md @@ -19,8 +19,8 @@ 2. **运行设置脚本(使用Bypass参数绕过执行策略)** ```powershell - cd "C:\Users\12742\Desktop\douyin_guaji-main" - powershell.exe -ExecutionPolicy Bypass -File ".\setup_auto_commit.ps1" + cd "<项目根目录>" + powershell.exe -ExecutionPolicy Bypass -File ".\scripts\setup_auto_commit.ps1" ``` 3. **完成!** 脚本会自动创建定时任务,每小时自动提交和推送代码。 @@ -51,8 +51,8 @@ 1. 选择"启动程序" 2. 点击"下一步" 3. 程序或脚本:输入 `powershell.exe` -4. 添加参数:输入 `-ExecutionPolicy Bypass -File "C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1"` -5. 起始于:输入 `C:\Users\12742\Desktop\douyin_guaji-main` +4. 添加参数:输入 `-ExecutionPolicy Bypass -File "<项目根目录>\scripts\auto_commit_push.ps1"` +5. 起始于:输入 `<项目根目录>` 6. 点击"下一步" ### 步骤5:完成设置 @@ -85,7 +85,9 @@ 您也可以使用以下PowerShell命令(以管理员身份运行)快速创建任务: ```powershell -$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -File `"C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1`"" -WorkingDirectory "C:\Users\12742\Desktop\douyin_guaji-main" +$projectRoot = "<项目根目录>" +$scriptPath = Join-Path $projectRoot "scripts\auto_commit_push.ps1" +$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -File `"$scriptPath`"" -WorkingDirectory $projectRoot $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Hours 1) -RepetitionDuration (New-TimeSpan -Days 365) @@ -130,4 +132,3 @@ Register-ScheduledTask -TaskName "Git自动提交推送" -Action $action -Trigge 4. 切换到"触发器"选项卡 5. 编辑触发器,修改重复间隔 6. 保存更改 - diff --git a/docs/高价值房间重访功能说明.md b/docs/高价值房间重访功能说明.md index 5b19293..323180e 100644 --- a/docs/高价值房间重访功能说明.md +++ b/docs/高价值房间重访功能说明.md @@ -148,4 +148,4 @@ python run_cli.py --high-value-room-revisit-only-current-run 2. **价值预测**:基于历史数据预测房间价值潜力 3. **多策略**:支持不同的重访策略选择 4. **统计报告**:生成重访效果统计报告 -c:\Users\12742\Desktop\douyin_guaji-main\docs\高价值房间重访功能说明.md \ No newline at end of file +docs\高价值房间重访功能说明.md diff --git a/douyin/fudai/douyin_fudai_flow.py b/douyin/fudai/douyin_fudai_flow.py index 680c1a0..aa528a8 100644 --- a/douyin/fudai/douyin_fudai_flow.py +++ b/douyin/fudai/douyin_fudai_flow.py @@ -6,7 +6,7 @@ douyin_fudai_flow 代理模块(WebGUI 根目录) 完整的流程辅助函数实现位于: - C:\\Users\\12742\\.cursor\\worktrees\\douyin_guaji-main\\axf\\douyin_fudai_flow.py + 环境变量 EXTERNAL_DOUYIN_FUDAI_DIR 指向的目录下的 douyin_fudai_flow.py 本模块的作用: 1. 动态加载上述外部模块; @@ -25,27 +25,20 @@ from types import ModuleType from typing import Any, Callable -# 使用环境变量或默认路径,避免硬编码用户路径 -_EXTERNAL_DIR = os.environ.get( - "EXTERNAL_DOUYIN_FUDAI_DIR", - os.path.join( - os.path.expanduser("~"), - ".cursor", - "worktrees", - "douyin_guaji-main", - "axf" - ) +_EXTERNAL_DIR = os.environ.get("EXTERNAL_DOUYIN_FUDAI_DIR", "").strip() +_EXTERNAL_PATH = ( + os.path.join(_EXTERNAL_DIR, "douyin_fudai_flow.py") if _EXTERNAL_DIR else "" ) -_EXTERNAL_PATH = os.path.join(_EXTERNAL_DIR, "douyin_fudai_flow.py") def _load_external_flow_module() -> ModuleType: - if not os.path.isfile(_EXTERNAL_PATH): + if not _EXTERNAL_PATH or not os.path.isfile(_EXTERNAL_PATH): # 如果外部文件不存在,创建一个空的模块 import types empty_module = types.ModuleType("douyin_fudai_flow_external") empty_module.__file__ = _EXTERNAL_PATH empty_module.__doc__ = "Empty fallback module - external douyin_fudai_flow.py not found" + empty_module.__dict__["_is_empty_fallback"] = True return empty_module mod_name = "douyin_fudai_flow_external" @@ -66,7 +59,7 @@ _ext_mod = _load_external_flow_module() # 先将外部模块中所有公开符号导出到当前命名空间 # 只有当外部模块不是空模块时才导出符号 -if hasattr(_ext_mod, '__file__') and _ext_mod.__file__ != _EXTERNAL_PATH: +if not getattr(_ext_mod, "_is_empty_fallback", False): # 外部文件存在且已加载,导出其符号 for _name, _value in list(vars(_ext_mod).items()): # type: ignore[arg-type] if _name.startswith("_"): diff --git a/gui/webgui_launcher.py b/gui/webgui_launcher.py index 59f00f9..0660c5a 100644 --- a/gui/webgui_launcher.py +++ b/gui/webgui_launcher.py @@ -15,8 +15,9 @@ from pathlib import Path import tkinter as tk from tkinter import ttk, scrolledtext, messagebox -# 获取脚本所在目录 +# 获取脚本所在目录和项目根目录 BASE_DIR = Path(__file__).parent.absolute() +PROJECT_ROOT = BASE_DIR.parent LOG_FILE = BASE_DIR / "webgui_startup.log" WEB_GUI_PY = BASE_DIR / "web_gui.py" @@ -196,7 +197,7 @@ class WebGUILauncher: try: # 检查是否有虚拟环境 - venv_python = BASE_DIR / ".venv" / "Scripts" / "python.exe" + venv_python = PROJECT_ROOT / ".venv" / "Scripts" / "python.exe" if venv_python.exists(): python_exe = str(venv_python) self.log("使用虚拟环境启动...") @@ -212,7 +213,7 @@ class WebGUILauncher: self.webgui_process = subprocess.Popen( [python_exe, str(WEB_GUI_PY)], - cwd=str(BASE_DIR), + cwd=str(PROJECT_ROOT), env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, diff --git a/gui_app.py b/gui_app.py new file mode 100644 index 0000000..29480f0 --- /dev/null +++ b/gui_app.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +"""Compatibility launcher for the desktop GUI.""" + +from __future__ import annotations + +import os +import runpy +import sys +from pathlib import Path + + +ROOT_DIR = Path(__file__).resolve().parent +TARGET = ROOT_DIR / "gui" / "gui_app.py" +VENV_PYTHON = ROOT_DIR / ".venv" / "Scripts" / "python.exe" + + +def _reexec_with_venv() -> None: + if not VENV_PYTHON.exists(): + return + if Path(sys.executable).resolve() == VENV_PYTHON.resolve(): + return + os.execv(str(VENV_PYTHON), [str(VENV_PYTHON), str(TARGET), *sys.argv[1:]]) + + +def main() -> None: + _reexec_with_venv() + sys.argv = [str(TARGET), *sys.argv[1:]] + runpy.run_path(str(TARGET), run_name="__main__") + + +if __name__ == "__main__": + main() diff --git a/run_cli.py b/run_cli.py index 8abfac9..9dc6927 100644 --- a/run_cli.py +++ b/run_cli.py @@ -40,18 +40,11 @@ except Exception: pass # ==== 兼容导入完整逻辑模块 douyin_fudai 及其依赖 ============================== -# 当前 WebGUI 目录中没有完整版 douyin_fudai.py,而是在 Cursor 的工作树中存在完整实现。 -# 同时,我们在本目录下放置了一些 shim 模块(如 douyin_text_utils、douyin_swipe_ops 等), -# 需要优先加载这些本地实现,再去加载完整逻辑模块。 +# 如果需要从外部工作树加载兼容模块,可显式设置 EXTERNAL_DOUYIN_FUDAI_DIR。 +# 默认只使用当前仓库内置实现,避免绑定到某台机器的 Cursor worktree 路径。 _BASE_DIR = os.path.dirname(__file__) -# 使用环境变量或默认路径,避免硬编码用户路径 -_EXTERNAL_DOUYIN_FUDAI_DIR = os.environ.get( - "EXTERNAL_DOUYIN_FUDAI_DIR", - os.path.join( - os.path.expanduser("~"), ".cursor", "worktrees", "douyin_guaji-main", "axf" - ), -) +_EXTERNAL_DOUYIN_FUDAI_DIR = os.environ.get("EXTERNAL_DOUYIN_FUDAI_DIR", "").strip() def _load_local_shim(mod_name: str, rel_path: str) -> None: diff --git a/scripts/auto_commit_push.bat b/scripts/auto_commit_push.bat index 8606df2..82c420d 100644 --- a/scripts/auto_commit_push.bat +++ b/scripts/auto_commit_push.bat @@ -1,11 +1,17 @@ @echo off -REM Git自动提交和推送批处理脚本 -REM 每小时自动保存修改、提交并推送到GitHub +REM Git auto commit and push batch launcher. +REM Runs the PowerShell script from this scripts directory. -cd /d "C:\Users\12742\Desktop\douyin_guaji-main" +cd /d "%~dp0.." +if errorlevel 1 ( + echo Failed to switch to project root. + pause + exit /b 1 +) -REM 运行PowerShell脚本 -powershell.exe -ExecutionPolicy Bypass -File "%~dp0auto_commit_push.ps1" +REM Run the PowerShell script. +powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0auto_commit_push.ps1" +set "EXIT_CODE=%ERRORLEVEL%" pause - +exit /b %EXIT_CODE% diff --git a/scripts/auto_commit_push.ps1 b/scripts/auto_commit_push.ps1 index 73d7329..c2a9543 100644 --- a/scripts/auto_commit_push.ps1 +++ b/scripts/auto_commit_push.ps1 @@ -4,10 +4,39 @@ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $ErrorActionPreference = "Stop" -# Switch to project directory -$projectPath = "C:\Users\12742\Desktop\douyin_guaji-main" +# Switch to project directory (parent of this scripts directory) +$projectPath = Resolve-Path (Join-Path $PSScriptRoot "..") Set-Location $projectPath +function Ensure-GitOnPath { + if (Get-Command git -ErrorAction SilentlyContinue) { + return + } + + $candidateDirs = @( + "C:\Program Files\Git\cmd", + "C:\Program Files\Git\bin", + "C:\Program Files (x86)\Git\cmd", + "C:\Program Files (x86)\Git\bin", + (Join-Path $env:LOCALAPPDATA "Programs\Git\cmd"), + (Join-Path $env:LOCALAPPDATA "Programs\Git\bin"), + "C:\ProgramData\chocolatey\bin" + ) + + foreach ($dir in $candidateDirs) { + if ($dir -and (Test-Path -LiteralPath (Join-Path $dir "git.exe"))) { + $env:Path = "$dir;$env:Path" + if (Get-Command git -ErrorAction SilentlyContinue) { + return + } + } + } + + throw "Git executable not found. Please install Git or add git.exe to PATH." +} + +Ensure-GitOnPath + # Get current timestamp $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" @@ -49,4 +78,3 @@ try { Write-Host "Stack trace: $($_.ScriptStackTrace)" -ForegroundColor Red exit 1 } - diff --git a/scripts/setup_auto_commit.ps1 b/scripts/setup_auto_commit.ps1 index efc6c9b..51c82b9 100644 --- a/scripts/setup_auto_commit.ps1 +++ b/scripts/setup_auto_commit.ps1 @@ -14,8 +14,8 @@ if (-not $isAdmin) { } $taskName = "Git自动提交推送" -$scriptPath = "C:\Users\12742\Desktop\douyin_guaji-main\auto_commit_push.ps1" -$workingDir = "C:\Users\12742\Desktop\douyin_guaji-main" +$scriptPath = Join-Path $PSScriptRoot "auto_commit_push.ps1" +$workingDir = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path Write-Host "========================================" -ForegroundColor Cyan Write-Host "Setting up Git Auto Commit Task" -ForegroundColor Cyan @@ -100,4 +100,3 @@ try { } pause - diff --git a/webgui_launcher.py b/webgui_launcher.py new file mode 100644 index 0000000..3ed9607 --- /dev/null +++ b/webgui_launcher.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +"""Compatibility launcher for the Web GUI launcher window.""" + +from __future__ import annotations + +import os +import runpy +import sys +from pathlib import Path + + +ROOT_DIR = Path(__file__).resolve().parent +TARGET = ROOT_DIR / "gui" / "webgui_launcher.py" +VENV_PYTHON = ROOT_DIR / ".venv" / "Scripts" / "python.exe" + + +def _reexec_with_venv() -> None: + if not VENV_PYTHON.exists(): + return + if Path(sys.executable).resolve() == VENV_PYTHON.resolve(): + return + os.execv(str(VENV_PYTHON), [str(VENV_PYTHON), str(TARGET), *sys.argv[1:]]) + + +def main() -> None: + _reexec_with_venv() + sys.argv = [str(TARGET), *sys.argv[1:]] + runpy.run_path(str(TARGET), run_name="__main__") + + +if __name__ == "__main__": + main()