feat(765-6): 초기값 사본에서 배수 공유 캐시 뺌 · 복원은 노선 몫만 갈음(캐시 제자리) · 복제가 설계 벌 묶음 안 지표면 id 고침
- common_util_initial_snapshot: 배수 사본 = 노선 몫만(하강장 · 도엽 좌표 · 강우 뺌 · 약 105 → 20 MB) · 복원은 폴더 통째 지우지 않음 · 캐시 든 옛 사본의 캐시 칸은 건너뜀 - common_util_project_copy._fix_files(통째 복제 · --replace 같은 길): design_sets/<지형>/ 의 db.json · 그 벌 초기값 · B06 표본 설정 · meta.json 지표면 id → 새 id · 노선 id 는 꺼낼 때 늘 새로 받아 안 고침 · 코리도 안 건드림 - 시험 test_765_design_sets 에 둘 덧 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -158,18 +158,68 @@ def _fix_files(
|
||||
print("프로젝트 id 치환:", replace_project_id(new_root, source_id, new_id))
|
||||
print("노선 · 지표면 id 파일:", rekey_id_files(new_root, model_map, route_map))
|
||||
|
||||
snapshot = new_root / "initial_snapshot" / "db.json"
|
||||
if snapshot.is_file():
|
||||
dump = json.loads(snapshot.read_text(encoding="utf-8"))
|
||||
changed = False
|
||||
for route in dump.get("routes", []):
|
||||
old_model = route.get("surface_model_id")
|
||||
if old_model in model_map:
|
||||
route["surface_model_id"] = model_map[old_model]
|
||||
changed = True
|
||||
if changed:
|
||||
snapshot.write_text(json.dumps(dump, ensure_ascii=False), encoding="utf-8")
|
||||
print("초기값 스냅샷 지표면 id 교정:", changed)
|
||||
print(
|
||||
"초기값 스냅샷 지표면 id 교정:", _fix_dump_models(new_root / "initial_snapshot", model_map)
|
||||
)
|
||||
print("설계 벌 묶음 지표면 id 교정:", _fix_design_sets(new_root, model_map))
|
||||
|
||||
|
||||
def _fix_dump_models(folder: Path, model_map: dict) -> bool:
|
||||
"""`folder/db.json` 노선 행의 지표면 id → 새 id · 바꿨으면 참."""
|
||||
path = folder / "db.json"
|
||||
if not path.is_file():
|
||||
return False
|
||||
dump = json.loads(path.read_text(encoding="utf-8"))
|
||||
changed = False
|
||||
for route in dump.get("routes", []):
|
||||
old_model = route.get("surface_model_id")
|
||||
if old_model in model_map:
|
||||
route["surface_model_id"] = model_map[old_model]
|
||||
changed = True
|
||||
if changed:
|
||||
path.write_text(json.dumps(dump, ensure_ascii=False), encoding="utf-8")
|
||||
return changed
|
||||
|
||||
|
||||
def _fix_sampling(root: Path, model_map: dict) -> bool:
|
||||
"""`B06_Section/sampling.json` 의 지표면 id → 새 id(코리도는 안 건드림)."""
|
||||
path = root / "B06_Section" / "sampling.json"
|
||||
if not path.is_file():
|
||||
return False
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
if data.get("surface_model_id") not in model_map:
|
||||
return False
|
||||
data["surface_model_id"] = model_map[data["surface_model_id"]]
|
||||
path.write_text(json.dumps(data, ensure_ascii=False), encoding="utf-8")
|
||||
return True
|
||||
|
||||
|
||||
def _fix_design_sets(root: Path, model_map: dict) -> dict[str, list[str]]:
|
||||
"""쉬는 설계 벌 묶음(765-6) 안 지표면 id → 새 id — db.json · 그 벌 초기값 · B06 표본 설정 ·
|
||||
meta.json. 노선 id 는 꺼낼 때 늘 새로 받아(묶음 안에서만 짝) 안 고침 → 묶음 → 고친 자리."""
|
||||
from common_util.common_util_design_sets import sets_dir
|
||||
|
||||
report: dict[str, list[str]] = {}
|
||||
base = sets_dir(root)
|
||||
for bundle in sorted(base.iterdir()) if base.is_dir() else []:
|
||||
fixed = [
|
||||
name
|
||||
for name, done in (
|
||||
("db.json", _fix_dump_models(bundle, model_map)),
|
||||
("initial_snapshot", _fix_dump_models(bundle / "initial_snapshot", model_map)),
|
||||
("sampling", _fix_sampling(bundle / "files", model_map)),
|
||||
)
|
||||
if done
|
||||
]
|
||||
meta_path = bundle / "meta.json"
|
||||
if meta_path.is_file():
|
||||
meta = json.loads(meta_path.read_text(encoding="utf-8"))
|
||||
if meta.get("model_id") in model_map:
|
||||
meta["model_id"] = model_map[meta["model_id"]]
|
||||
meta_path.write_text(json.dumps(meta, ensure_ascii=False), encoding="utf-8")
|
||||
fixed.append("meta.json")
|
||||
report[bundle.name] = fixed
|
||||
return report
|
||||
|
||||
|
||||
def _write_manifest(root: Path, manifest: dict[str, Any]) -> None:
|
||||
|
||||
Reference in New Issue
Block a user