fix: Adjust configuration settings and improve error handling
- Updated `config.json` to modify `yanghao_recommend_interval_seconds` for better timing control. - Refactored logging in `douyin_detection.py` to enhance readability and error handling. - Improved pixel loading and error management in image processing functions across multiple modules. - Enhanced GUI elements in `gui_app.py` to support new configuration options and improve user experience.
This commit is contained in:
1 parent
47e6b016c5
commit
2cd81c05a3
35 files changed
+12043
-1711
No files matched your search
@@ -117,6 +117,57 @@ def ensure_dir(path: str) -> None:
|
||||
os.makedirs(dir_path, exist_ok=True)
|
||||
|
||||
|
||||
def find_executable(cmd: str) -> str | None:
|
||||
"""尝试在系统环境中定位可执行命令的完整路径。
|
||||
|
||||
处理策略:
|
||||
- 若 `cmd` 已是存在的路径则直接返回;
|
||||
- 使用 `shutil.which` 尝试查找;
|
||||
- 在 Windows 上回退到 `where`,在类 Unix 上回退到 `command -v` / `which`。
|
||||
|
||||
返回命令的绝对路径,找不到时返回 `None`。
|
||||
"""
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
|
||||
if not cmd:
|
||||
return None
|
||||
# 如果传入的是已有文件路径,直接返回绝对路径
|
||||
if os.path.exists(cmd):
|
||||
return os.path.abspath(cmd)
|
||||
|
||||
# 首选 shutil.which
|
||||
try:
|
||||
found = shutil.which(cmd)
|
||||
if found:
|
||||
return found
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 平台回退检查
|
||||
try:
|
||||
if sys.platform.startswith("win"):
|
||||
# 使用 where 查找(Windows)
|
||||
proc = subprocess.run(["where", cmd], capture_output=True, text=True)
|
||||
if proc.returncode == 0 and proc.stdout:
|
||||
first = proc.stdout.splitlines()[0].strip()
|
||||
if first:
|
||||
return first
|
||||
else:
|
||||
# 类 Unix:尝试 command -v 再 which
|
||||
proc = subprocess.run(["/bin/sh", "-c", f"command -v {cmd} || which {cmd}"], capture_output=True, text=True)
|
||||
if proc.returncode == 0 and proc.stdout:
|
||||
first = proc.stdout.splitlines()[0].strip()
|
||||
if first:
|
||||
return first
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user