r"""D:\\Rhino-MCP 하위 경로를 Pier_T_rebar\Code 하위 경로로 치환한다 (2026-10-28). - 치환 전 원본을 backup\경로치환_20261028\ 에 같은 상대경로로 보관한다. - 변경 내역을 JSON으로 남긴다 (엑셀 관리리스트의 입력). 사용: python migrate_paths_20261028.py <결과 json> """ import json, shutil, sys from pathlib import Path root = Path(sys.argv[1]) out = Path(sys.argv[2]) code = str(root / "Code") pairs = [ (r"D:\Rhino-MCP\rhino-mcp-main\rhino_mcp", code + r"\rhino_mcp"), (r"D:\Rhino-MCP\rhino-mcp-main\rebar_pipeline", code + r"\rebar_pipeline"), (r"D:\Rhino-MCP\rhino-mcp-main\review_pipeline", code + r"\review_pipeline"), (r"D:\Rhino-MCP\pier-program", code + r"\pier-program"), ] # JSON 이스케이프(\) 표기도 함께 처리 pairs += [(a.replace("\\", "\\\\"), b.replace("\\", "\\\\")) for a, b in pairs] skip_dirs = {"node_modules", "RAG", "backup", "temp", ".venv", ".git", ".hmcmkit", "__pycache__", "memory"} skip_files = {"migrate_paths_20261028.py", "CLAUDE.local.md", "HANDOFF.md", "Rhino_MCP_연결실행.bat"} exts = {".md", ".txt", ".py", ".json", ".ps1", ".js"} bk = root / "backup" / "경로치환_20261028" log = [] for p in root.rglob("*"): if not p.is_file() or p.suffix.lower() not in exts or p.name in skip_files: continue if any(part in skip_dirs for part in p.relative_to(root).parts): continue try: t = p.read_text(encoding="utf-8") except Exception: continue n = t for a, b in pairs: n = n.replace(a, b) if n != t: rel = p.relative_to(root) (bk / rel).parent.mkdir(parents=True, exist_ok=True) shutil.copy2(p, bk / rel) p.write_text(n, encoding="utf-8", newline="") log.append({"file": str(rel), "count": sum(t.count(a) for a, _ in pairs)}) out.write_text(json.dumps(log, ensure_ascii=False, indent=1), encoding="utf-8") print(len(log), "files changed")