Files
douyi_guaji_main/douyin/handlers/screenshot_manager/__init__.py
T
CodexandClaude Opus 4.7 bf7f30996e 拆分 douyin_screenshot_manager (1705 → 6 个子模块 + 79 行 shim)
把巨型文件 douyin/handlers/douyin_screenshot_manager.py 按职责拆成
douyin/handlers/screenshot_manager/ 子包:

- _common (79)     共享 logger / 全局状态 / 异步计数器
- paths (205)      OCR 目录、调试存档目录、各类路径
- save_files (173) save_latest_attempt / save_last_success / save_*_from_file / cleanup_ocr_dir
- async_save (360) _debug_save_loop + 工作线程启停(global 状态走 _common._state.X)
- cleanup (293)    debug_captures 目录清理与轮转
- save_image (731) save_debug_image 主入口(最大头)

原文件改为 79 行 re-export shim,30 个公共符号全部保留。
外部 29 处 save_debug_image / 6 处 save_latest_attempt / 等
import 路径不变,零调用方修改。

回归:
- 子包 7 文件 + shim compileall 通过
- pytest 353 passed / 1 skipped(与拆分前完全一致)
- 旧 import 路径与新子包路径返回同一函数对象
- AST 验证 30 个期望符号全部正确暴露

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 16:25:59 +08:00

85 lines
2.3 KiB
Python

from __future__ import annotations
"""screenshot_manager - 截图管理子包(双截图记录 + 异步调试保存)。
原 douyin/handlers/douyin_screenshot_manager.py 拆成 6 个子模块:
- _common 共享 logger / 全局状态 / 异步计数器
- paths OCR 目录、调试存档目录、各类路径计算
- save_files save_latest_attempt / save_last_success / save_*_from_file / cleanup_ocr_dir
- async_save _debug_save_loop + 工作线程启停
- cleanup debug_captures 目录的清理与轮转
- save_image save_debug_image 主入口
外部 import 路径不变:from douyin.handlers.douyin_screenshot_manager import save_debug_image
仍能工作(原文件改为 re-export shell)。
"""
from ._common import (
_LOGGER,
_mgr_log,
_debug_save_queue,
_debug_save_worker_lock,
_debug_save_shutdown_event,
_async_save_counters_lock,
_SKIP_DEBUG_SAVE_IN_HOTLOOPS,
get_async_save_counters,
reset_async_save_counters,
)
from .paths import (
get_ocr_dir,
get_category_for_picname,
get_latest_attempt_path,
get_last_success_path,
ensure_ocr_dir,
get_debug_captures_dir,
ensure_debug_captures_dir,
get_debug_captures_base_dir,
)
from .save_files import (
cleanup_ocr_dir,
save_latest_attempt,
save_last_success,
save_attempt_from_file,
save_success_from_file,
)
from .async_save import (
_debug_save_loop,
_ensure_debug_save_worker_started,
shutdown_debug_save_worker,
)
from .cleanup import (
count_debug_captures_files,
cleanup_debug_captures,
init_debug_captures_cleanup,
)
from .save_image import (
_sanitize_filename_part,
save_debug_image,
)
__all__ = [
"_LOGGER",
"_mgr_log",
"get_async_save_counters",
"reset_async_save_counters",
"get_ocr_dir",
"get_category_for_picname",
"get_latest_attempt_path",
"get_last_success_path",
"ensure_ocr_dir",
"get_debug_captures_dir",
"ensure_debug_captures_dir",
"get_debug_captures_base_dir",
"cleanup_ocr_dir",
"save_latest_attempt",
"save_last_success",
"save_attempt_from_file",
"save_success_from_file",
"shutdown_debug_save_worker",
"count_debug_captures_files",
"cleanup_debug_captures",
"init_debug_captures_cleanup",
"save_debug_image",
]