Files
SceneMarshal/media/src/core/shell.py
T

25 lines
955 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# src/core/shell.py
import shutil
import subprocess
from core import config
from .exceptions import MediaDependencyError
from .logger import log # 💡 引入日志
def check_dependencies():
"""检查系统依赖是否已正确安装(列表见 config.ini [System] required_tools)"""
tools = list(config.REQUIRED_TOOLS)
log.debug(f"正在检查系统依赖: {', '.join(tools)}")
missing = [tool for tool in tools if not shutil.which(tool)]
if missing:
error_msg = f"容器内缺少必要依赖: {', '.join(missing)}"
log.critical(error_msg) # 💡 致命错误级别
raise MediaDependencyError(error_msg)
log.debug("所有系统依赖检查通过。")
def run_command(cmd: list) -> subprocess.CompletedProcess:
"""安全执行终端命令"""
log.debug(f"执行系统命令: {' '.join(cmd)}")
return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)