#!/usr/bin/env python3 from pathlib import Path from collections import defaultdict import argparse import re ROOT = Path(__file__).resolve().parent.parent EXCLUDED_DIRS = { ".git", ".xmake", "build", "install", "log", "__pycache__", ".cache", } EXCLUDED_FILES = { "compile_commands.json", "CMakeCache.txt", } # 匹配 Linux 绝对路径,避免匹配 URL 中的 // PATH_PATTERN = re.compile( r'(? 140: excerpt = excerpt[:137] + "..." findings.append({ "file": str(relative), "line": line_no, "path": path, "category": category, "excerpt": excerpt, }) print("=" * 72) print("仓库绝对路径审计报告") print("=" * 72) print(f"仓库:{ROOT}") print(f"扫描文件数:{file_count}") print(f"发现路径数:{len(findings)}") print() print("[分类统计]") for category, count in sorted(category_counts.items()): print(f" {category:<18} {count:>5}") print() limit = len(findings) if args.all else max(0, args.max_lines) shown = findings[:limit] current_file = None for item in shown: if item["file"] != current_file: current_file = item["file"] print(f"\n[{current_file}]") print( f" L{item['line']:<5} " f"[{item['category']}] {item['path']}" ) print(f" {item['excerpt']}") remaining = len(findings) - len(shown) print("\n" + "=" * 72) print(f"已显示:{len(shown)} / {len(findings)}") if remaining: print(f"其余隐藏:{remaining} 条") print("需要完整报告时执行:python3 tools/audit_absolute_paths.py --all") print("=" * 72) if __name__ == "__main__": main()