| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #!/usr/bin/env python3
- """MathLab 环境检查脚本"""
- import os
- import sys
- import subprocess
- from pathlib import Path
- def check_command(cmd: str) -> bool:
- """检查命令是否可用"""
- try:
- result = subprocess.run(["which", cmd], capture_output=True, text=True)
- return result.returncode == 0
- except:
- return False
- def check_directory(path: str, required: bool = False) -> bool:
- """检查目录是否存在"""
- exists = os.path.exists(path)
- status = "✅" if exists else ("❌" if required else "⚠️")
- print(f"{status} {path}")
- return exists
- def main():
- print("=" * 50)
- print("🔧 MathLab 环境检查")
- print("=" * 50)
-
- # 必需命令
- print("\n📦 必需命令:")
- required_commands = ["python3", "git", "pytest"]
- for cmd in required_commands:
- available = check_command(cmd)
- if not available:
- print(f" ❌ {cmd} 未安装,请运行:sudo apt install {cmd}")
-
- # PDF 转换工具
- print("\n📄 PDF 转换工具:")
- pdf_tools = ["pdftotext", "marker_single", "pdf2md"]
- found = False
- for tool in pdf_tools:
- if check_command(tool):
- found = True
- print(f" ✅ {tool} (可用)")
- break
- if not found:
- print(" ⚠️ 未找到 PDF 转换工具,建议安装 pdftotext")
-
- # Python 依赖
- print("\n🐍 Python 依赖:")
- python_deps = ["numpy", "matplotlib", "jinja2", "pyyaml"]
- try:
- import importlib
- for dep in python_deps:
- try:
- importlib.import_module(dep)
- print(f" ✅ {dep}")
- except ImportError:
- print(f" ❌ {dep} - 请运行:pip3 install {dep}")
- except Exception as e:
- print(f" ❌ 检查失败:{e}")
-
- # 目录结构
- print("\n📁 目录结构:")
- base_dir = Path(__file__).parent.parent.parent
- directories = [
- (base_dir / "textbook", False),
- (base_dir / "staging", False),
- (base_dir / "courseware", True),
- (base_dir / "exercises", True),
- (base_dir / "tests", True),
- ]
- for dir_path, required in directories:
- check_directory(str(dir_path), required)
-
- # Git 配置
- print("\n🔄 Git 配置:")
- try:
- result = subprocess.run(
- ["git", "remote", "get-url", "origin"],
- capture_output=True, text=True, cwd=base_dir
- )
- if result.returncode == 0:
- remote_url = result.stdout.strip()
- if "example.com" in remote_url:
- print(f" ⚠️ Git remote 是示例地址:{remote_url}")
- print(f" 💡 请运行:git remote set-url origin \<你的 Gogs 地址>")
- else:
- print(f" ✅ Git remote: {remote_url}")
- else:
- print(f" ❌ Git remote 未配置")
- except Exception as e:
- print(f" ❌ Git 检查失败:{e}")
-
- print("\n" + "=" * 50)
- print("✅ 环境检查完成")
- print("=" * 50)
- if __name__ == "__main__":
- main()
|