diff --git a/backup/__init__.py b/backup/__init__.py new file mode 100644 index 0000000..778a2d4 --- /dev/null +++ b/backup/__init__.py @@ -0,0 +1 @@ +# 使 backup 成为显式包,便于 from backup.msg_push import ... diff --git a/src/utils.py b/src/utils.py index 77326dc..5857add 100644 --- a/src/utils.py +++ b/src/utils.py @@ -11,15 +11,16 @@ import functools import hashlib import re import traceback -from typing import Any, List, Optional, Union +from typing import Any, Dict, List, Optional, Union from urllib.parse import parse_qs, urlparse from collections import OrderedDict import execjs from .logger import logger import configparser -OptionalStr = Optional[str] -OptionalDict = Optional[dict] +# Python 3.9:此处不能写 str | None(| 会在 import 时求值报错),勿改回 PEP604 写法 +OptionalStr = Union[str, None] +OptionalDict = Union[Dict[str, Any], None] class Color: diff --git a/tools/deploy_live_paramiko.py b/tools/deploy_live_paramiko.py index 48d095a..61e1efd 100644 --- a/tools/deploy_live_paramiko.py +++ b/tools/deploy_live_paramiko.py @@ -24,7 +24,25 @@ REMOTE_BASE = os.environ.get("LIVE_DEPLOY_PATH", "/home/live/douyinyoutube").rst REPO_ROOT = Path(__file__).resolve().parent.parent + +def _discover_repo_files() -> list[str]: + """与 youtube.py 运行相关的源码,避免只同步白名单时缺模块。""" + extra: list[str] = [] + backup_dir = REPO_ROOT / "backup" + if backup_dir.is_dir(): + for p in sorted(backup_dir.glob("*.py")): + extra.append(str(p.relative_to(REPO_ROOT)).replace("\\", "/")) + return extra + + FILES = [ + "src/utils.py", + "src/logger.py", + "src/spider.py", + "src/stream.py", + "src/proxy.py", + "src/http_clients/async_http.py", + "src/http_clients/sync_http.py", "src/android_control.py", "src/async_thread_loop.py", "src/youtube_ini_sync.py", @@ -37,6 +55,7 @@ FILES = [ "youtube.py", "tiktok.py", "main.py", + "ffmpeg_install.py", "scripts/hardware_probe.py", "config/hardware.env.example", "ecosystem.config.cjs", @@ -73,6 +92,8 @@ FILES = [ "web-console/components/console/LiveConsoleWorkspace.tsx", ] +FILES = sorted(set(FILES + _discover_repo_files())) + LOG_DIR = REPO_ROOT / ".deploy_logs" TAIL_LINES = 90 @@ -229,8 +250,26 @@ def main() -> int: sftp_put(sftp, lp, rp) _safe_print(f"已上传: {rel}") + run_logged( + client, + log_path, + "clear_python_caches", + f"rm -rf {REMOTE_BASE}/src/__pycache__ {REMOTE_BASE}/backup/__pycache__ 2>/dev/null; echo cache_cleared", + timeout=20, + ) + run_logged( + client, + log_path, + "verify_utils_py_snippet", + f"sed -n '1,28p' {REMOTE_BASE}/src/utils.py", + timeout=15, + ) + py_compile = ( - f"cd {REMOTE_BASE} && python3 -m py_compile web.py youtube.py tiktok.py " + f"cd {REMOTE_BASE} && python3 -m py_compile web.py youtube.py tiktok.py ffmpeg_install.py " + "backup/__init__.py backup/msg_push.py backup/robust_relay.py " + "src/utils.py src/logger.py src/spider.py src/stream.py src/proxy.py " + "src/http_clients/async_http.py src/http_clients/sync_http.py " "src/control_plane.py src/web_process_backend.py src/hub_routes.py " "src/async_thread_loop.py src/youtube_ini_sync.py " "src/live_config/__init__.py src/live_config/loader.py "