From a1ecc1df3f47e3cc7dfd0346a89d15f4c1407ae7 Mon Sep 17 00:00:00 2001 From: umsangdon Date: Wed, 18 Nov 2026 02:22:06 +0900 Subject: [PATCH] =?UTF-8?q?refactor(855-F=20B9-5):=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=EC=A0=9D=ED=8A=B8=20=EC=98=9B=20=EC=82=AC=EB=B3=B8=20=EA=BC=B4?= =?UTF-8?q?=20=EC=9D=BD=EA=B8=B0=20=EA=B1=B7=EC=9D=8C=20=E2=80=94=20?= =?UTF-8?q?=EC=98=9B=20=ED=95=AD=EB=AA=A9=20=ED=8F=B4=EB=8D=94=20=EC=98=AE?= =?UTF-8?q?=EA=B2=A8=20=EB=B0=9B=EA=B8=B0=20=C2=B7=20=EC=98=9B=20=EB=B3=B5?= =?UTF-8?q?=EC=82=AC=EB=B3=B8=20=EC=B1=84=EC=9A=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - M02_Item_Snapshot: migrate_items · items_dir · OLD_ITEMS_DIRNAME · complete_old 지움 · 맞춤 답 「옮겨받음」 칸 뺌 - M02_Item_Copy: _migrated 대신 structures_dir · 읽을 때 complete_old 안 부름 - 까닭: 프로젝트 사본 0 · templates/items 0(보충 3-1 · 판단 거리 3 = 걷음) · 옛 꼴 호환 안 만듦(요구 898 · 899) - 시험: test_item_copy_complete 옛 꼴 둘(옛 복사본 채움 · 옛 항목 폴더 옮겨 받음) 지움 — 죽은 길만 붙듦 · test_structures_summary_snapshot 맞춤 답 칸 하나 고침 - 검증: 관련 시험 270 — 통과 267 · 실패 3 = test_719_2 셋(고치기 전부터 같은 실패 · 묶음 3 몫) Co-Authored-By: Claude Opus 5.5 --- M02_MasterTemplete/M02_Item_Copy.py | 20 +--- M02_MasterTemplete/M02_Item_Snapshot.py | 92 +------------------ resources/tester/test_item_copy_complete.py | 37 -------- .../test_structures_summary_snapshot.py | 2 +- 4 files changed, 9 insertions(+), 142 deletions(-) diff --git a/M02_MasterTemplete/M02_Item_Copy.py b/M02_MasterTemplete/M02_Item_Copy.py index 889bfae4b..32940c06b 100644 --- a/M02_MasterTemplete/M02_Item_Copy.py +++ b/M02_MasterTemplete/M02_Item_Copy.py @@ -4,7 +4,7 @@ 복사본 = `{프로젝트}/templates/structures/{구조물 id}/` (`M02_Item_Snapshot`) · 길의 폴더 = 구조물 id. 파일마다 판 = 내용 해시 — 쓸 때 판이 다르면 `Stale`(409). 고치면 manifest 에 `고침` 을 남겨 지울 때 -`_지난/` 에 옮겨 둠. 옛 복사본(새 파일 없음) · 옛 항목 폴더는 읽을 때 채우고 옮겨 받음. +`_지난/` 에 옮겨 둠. 계산은 복사본만 씀(마스터 현재값 안 읽음) — 원본 항목이 바뀌거나 지워져도 그대로. """ @@ -29,10 +29,7 @@ from M02_MasterTemplete.M02_Item_Snapshot import ( PICKS_FILE, VALUES_FILE, build_snapshot, - complete_old, folder_name, - items_dir, - migrate_items, now_text, retire, same_item, @@ -68,21 +65,13 @@ class Stale(ValueError): self.current = current -def _migrated(project_root: str | Path) -> Path: - """구조물 복사본 뿌리 — 옛 항목 폴더가 남았으면 먼저 옮겨 받음.""" - if items_dir(project_root).is_dir(): - migrate_items(project_root) - return structures_dir(project_root) - - def folder_of(project_root: str | Path, folder: str) -> Path: """구조물 복사본 폴더 — 이름 모양이 틀리거나 없으면 LookupError(404).""" if not FOLDER_PATTERN.match(folder): raise LookupError(f"복사본 폴더 이름 모양이 아님 「{folder}」") - target = _migrated(project_root) / folder + target = structures_dir(project_root) / folder if not (target / MANIFEST_NAME).is_file(): raise LookupError(f"복사본이 없음 「{folder}」") - complete_old(target) return target @@ -97,7 +86,7 @@ def source_changed(manifest: dict[str, Any]) -> bool | None: def list_items(project_root: str | Path, only: str | None = None) -> list[dict[str, Any]]: """복사본 목록 — `only` = 그 폴더 하나만(고르기 모달 · 원본 대조를 그 하나만 · 156-2).""" - base = _migrated(project_root) + base = structures_dir(project_root) out = [] for child in sorted(base.iterdir()) if base.is_dir() else []: if not child.is_dir() or not FOLDER_PATTERN.match(child.name): @@ -106,7 +95,6 @@ def list_items(project_root: str | Path, only: str | None = None) -> list[dict[s continue if not (child / MANIFEST_NAME).is_file(): continue - complete_old(child) manifest = read_json(child / MANIFEST_NAME) or {} origin = manifest.get("원본") or {} changed = source_changed(manifest) @@ -289,7 +277,7 @@ def prefetch(project_root: str | Path, owner_id: str, item: dict[str, Any]) -> d folder = folder_name(owner_id) if not FOLDER_PATTERN.match(folder): raise ValueError(f"구조물 id 모양이 아님 「{owner_id}」") - target = _migrated(project_root) / folder + target = structures_dir(project_root) / folder manifest = read_json(target / MANIFEST_NAME) made = not (isinstance(manifest, dict) and same_item(manifest, item)) if made: diff --git a/M02_MasterTemplete/M02_Item_Snapshot.py b/M02_MasterTemplete/M02_Item_Snapshot.py index cc9ebabaf..a6315b09e 100644 --- a/M02_MasterTemplete/M02_Item_Snapshot.py +++ b/M02_MasterTemplete/M02_Item_Snapshot.py @@ -13,8 +13,6 @@ - 지정을 다른 항목으로 바꾸면 새로 가져옴 · 구조물을 지우거나 지정을 풀면 복사본을 지움 — 프로젝트에서 고친 흔적(`manifest.고침`)이 있으면 지우지 않고 `_지난/` 에 옮겨 둠 - 관 지점을 옮겨도 같은 항목이면 폴더 이름만 바꿈(142-2) · 옵션 그룹 이름 · 가져온이도 굳힘 - - 옛 항목 폴더(`templates/items/{층}_{주인}_{키}/` · 25-2b)는 그 항목을 쓰는 구조물마다 복사해 - 옮겨 받음(고친 값 유지) """ from __future__ import annotations @@ -29,12 +27,11 @@ from B05_Profile.B05_Profile_Structures_Repository import load_structures from B05_Profile.B05_Profile_Structures_Schema import STRUCTURE_ID_RULE from common_util.common_util_drainage_pipes import pipe_points_path_in, read_pipe_points_file from common_util.common_util_json import atomic_write_json -from common_util.common_util_summary_item import GROUP_JOIN, snapshot_folder_name +from common_util.common_util_summary_item import GROUP_JOIN from common_util.common_util_time import kst_now, utc_now_text from M02_MasterTemplete import M02_Template_Layers as layers from M02_MasterTemplete.M02_Item_Source import ( LABOR_FILE, - PRICE_FILE, build_source, item_path, read_json, @@ -44,7 +41,6 @@ from M02_MasterTemplete.M02_Item_Source import ( logger = logging.getLogger(__name__) STRUCTURES_DIRNAME = "structures" -OLD_ITEMS_DIRNAME = "items" # 25-2b 항목 폴더 — 옮겨 받기만 PAST_DIRNAME = "_지난" # 고친 흔적이 있는 복사본을 지우지 않고 옮겨 두는 자리 MANIFEST_NAME = "manifest.json" VALUES_FILE = "입력값.json" # {로직키: {입력이름: {값, 확인}}} @@ -63,11 +59,6 @@ def structures_dir(project_root: str | Path) -> Path: return layers.project_dir(project_root) / STRUCTURES_DIRNAME -def items_dir(project_root: str | Path) -> Path: - """옛 항목 폴더 뿌리(25-2b) — 옮겨 받기에만 씀.""" - return layers.project_dir(project_root) / OLD_ITEMS_DIRNAME - - def folder_name(owner_id: str) -> str: """구조물 id → 복사본 폴더 이름 — id 없는 옛 구조물(`#차례`)은 `n차례`.""" return owner_id.replace("#", "n") @@ -195,42 +186,6 @@ def retire(folder: Path) -> str | None: return None -def migrate_items(project_root: str | Path) -> list[str]: - """옛 항목 폴더 → 그 항목을 쓰는 구조물마다 복사(고친 값 유지) — 옮겨 받은 구조물 폴더 이름. - - 다 옮긴 옛 폴더는 지움 · 쓰는 구조물이 없고 고친 흔적이 있으면 `structures/_지난/` 에 둠.""" - old = items_dir(project_root) - if not old.is_dir(): - return [] - base = structures_dir(project_root) - wanted = assignments(project_root) - moved: list[str] = [] - for child in sorted(p for p in old.iterdir() if p.is_dir()): - manifest = read_json(child / MANIFEST_NAME) - if not isinstance(manifest, dict): - continue - users = [o for o, item in wanted.items() if snapshot_folder_name(item) == child.name] - for owner in users: - target = safe_folder(base, folder_name(owner)) - if target is None or (target / MANIFEST_NAME).is_file(): - continue # 이미 새 복사본이 있음 - shutil.copytree(child, target, dirs_exist_ok=True) - origin = manifest.get("원본") or {} - atomic_write_json( - target / MANIFEST_NAME, - {**manifest, "원본": origin_of(origin), "구조물": [owner], "옮겨받음": now_text()}, - ) - moved.append(target.name) - if users or not manifest.get("고침"): - shutil.rmtree(child) - else: - (base / PAST_DIRNAME).mkdir(parents=True, exist_ok=True) - shutil.move(str(child), str(base / PAST_DIRNAME / f"items_{child.name}")) - if not any(old.iterdir()): - old.rmdir() - return moved - - def rename_moved(base: Path, wanted: dict[str, tuple[str, dict[str, Any]]]) -> list[str]: """관 지점을 옮긴 뒤 [저장] — 새 자리(`pipe@새 측점`)에 복사본이 없고 안 쓰게 된 옛 자리 복사본이 같은 항목 · 같은 그룹 꼬리면 폴더 이름만 바꿈(가까운 측점 먼저 · 142-2) — 가져온날 · @@ -313,9 +268,8 @@ def copied_groups( def sync_snapshots( project_root: str | Path, who: dict[str, Any] | None = None ) -> dict[str, list[str]]: - """구조물 복사본을 지정에 맞춤 — `{만듦, 지움, 못만듦, 옮겨받음, 이름바꿈}` 폴더 이름 · + """구조물 복사본을 지정에 맞춤 — `{만듦, 지움, 못만듦, 이름바꿈}` 폴더 이름 · `who` = 가져온이(manifest · 142-2).""" - moved = migrate_items(project_root) base = structures_dir(project_root) wanted = { folder_name(owner): (owner, item) for owner, item in assignments(project_root).items() @@ -357,7 +311,7 @@ def sync_snapshots( if child.is_dir() and not child.name.startswith("_") and child.name not in wanted: retire(child) removed.append(child.name) - out = {"만듦": made, "지움": removed, "못만듦": failed, "옮겨받음": moved} + out = {"만듦": made, "지움": removed, "못만듦": failed} return {**out, "이름바꿈": renamed} if renamed else out @@ -381,42 +335,6 @@ def safe_sync(project_root: str | Path, who: dict[str, Any] | None = None) -> li return ["*"] -def complete_old(folder: Path) -> bool: - """옛 복사본(21-3 · 새 파일 없음)을 채움 — 단가는 지금 원본에서 · 값은 빈 것. - - 옛 내용 파일(집계 · 도면 …)은 그대로 둠. 채웠으면 True(manifest 에 `옮겨받음` 날).""" - manifest = read_json(folder / MANIFEST_NAME) - if not isinstance(manifest, dict): - return False - lacking = [ - name for name in (PRICE_FILE, VALUES_FILE, PICKS_FILE) if not (folder / name).is_file() - ] - if not lacking and "원본판" in manifest: - return False - need_source = PRICE_FILE in lacking - try: - source = build_source(manifest["원본"]) if need_source else {} - except LookupError: - source = {} # 원본이 지워짐 — 빈 단가로(계산은 멈춤으로 알림) - for name in lacking: - atomic_write_json(folder / name, source.get(name, {})) - kept = { - name: read_json(folder / name) - for name in sorted(p.name for p in folder.glob("*.json")) - if name not in (MANIFEST_NAME, *LOCAL_FILES, "수식.json") # 수식 사본(802-4a) 원본판 밖 - } - atomic_write_json( - folder / MANIFEST_NAME, - { - **manifest, - "가져온날": manifest.get("가져온날") or manifest.get("적용일"), - "원본판": manifest.get("원본판") or version_of(kept), - "옮겨받음": manifest.get("옮겨받음") or now_text(), - }, - ) - return True - - #: 「연결된 사본」 부분 이름 → 파일(있는 것만 `부분` 에 담음) LINKED_PARTS = (("도면", "도면.json"), ("면적", "면적.json"), ("일위대가", LABOR_FILE)) @@ -446,8 +364,6 @@ def linked_snapshots(project_root: str | Path) -> dict[str, dict[str, Any]]: def read_snapshot(project_root: str | Path, owner_id: str) -> dict[str, Any] | None: - """그 구조물 복사본의 `집계.json`(`{줄, 열}`) — 없으면 None(옛 항목 폴더는 먼저 옮겨 받음).""" - if items_dir(project_root).is_dir(): - migrate_items(project_root) + """그 구조물 복사본의 `집계.json`(`{줄, 열}`) — 없으면 None.""" data = read_json(structures_dir(project_root) / folder_name(owner_id) / "집계.json") return data if isinstance(data, dict) else None diff --git a/resources/tester/test_item_copy_complete.py b/resources/tester/test_item_copy_complete.py index 23f08c5bb..046bf5f8d 100644 --- a/resources/tester/test_item_copy_complete.py +++ b/resources/tester/test_item_copy_complete.py @@ -300,23 +300,6 @@ def test_미리_가져오기(world): copies.prefetch(root, "../x", PIPE) -def test_옛_복사본은_읽을_때_채움(world): - root = world["root"] - _save(root, [_pipe()]) - folder = root / "templates/structures" / FOLDER - for name in ("입력값.json", "고른자재.json", "단가.json"): - (folder / name).unlink() - manifest = _read(folder / "manifest.json") - for key in ("원본판", "가져온날"): - manifest.pop(key) - (folder / "manifest.json").write_text(json.dumps(manifest, ensure_ascii=False), "utf-8") - assert copies.read_file(root, FOLDER, "입력값")["내용"] == {} - filled = _read(folder / "manifest.json") - assert filled["가져온날"] == filled["적용일"] and filled["옮겨받음"] - assert (folder / "단가.json").is_file() and copies.calc(root, FOLDER)["빠진입력"] - assert copies.list_items(root)[0]["마스터바뀜"] is False # 원본이 안 바뀐 옛 복사본 - - # ── 길 · 권한 ──────────────────────────────────────── @@ -489,26 +472,6 @@ def test_프로젝트에서_새_항목(world): copies.new_item(root, "c2", 3, 12, [], "", None) # 경로 · 이름 빈 값 -def test_옛_항목_폴더는_쓰는_구조물마다_옮겨_받음(world): - root = world["root"] - _save_all(root, [_wall("d1"), _wall("d2")], []) - base = root / "templates/structures" - old = root / "templates/items/system_none_SS000022" - old.parent.mkdir(parents=True) - shutil.move(str(base / "d1"), str(old)) - shutil.rmtree(base / "d2") - manifest = _read(old / "manifest.json") - manifest.update({"구조물": ["d1", "d2"], "고침": True}) - (old / "manifest.json").write_text(json.dumps(manifest, ensure_ascii=False), "utf-8") - (old / "입력값.json").write_text(json.dumps({"GF": {"a": {"값": 1}}}), "utf-8") - assert [i["폴더"] for i in copies.list_items(root)] == ["d1", "d2"] - assert not (root / "templates/items").exists() - for sid in ("d1", "d2"): - assert _read(base / sid / "입력값.json") == {"GF": {"a": {"값": 1}}} # 고친 값 유지 - assert _read(base / sid / "manifest.json")["구조물"] == [sid] - assert _save_all(root, [_wall("d1"), _wall("d2")], [])["만듦"] == [] - - def test_지정을_바꾸면_고친_옛_복사본은_지난에(world): root = world["root"] _save_all(root, [_wall("e1")], []) diff --git a/resources/tester/test_structures_summary_snapshot.py b/resources/tester/test_structures_summary_snapshot.py index 5b7c2b9f5..bae53e40a 100644 --- a/resources/tester/test_structures_summary_snapshot.py +++ b/resources/tester/test_structures_summary_snapshot.py @@ -129,7 +129,7 @@ def test_옛_파일은_칸_없음_그대로_읽고_씀(): def test_지정하면_폴더가_생기고_내용이_원본과_같음(world): root = world["root"] result = _save(root, [_dry(MS), _wet()], [_pipe(PIPE)]) - assert result == {"만듦": ["pipe@40.0", "st0"], "지움": [], "못만듦": [], "옮겨받음": []} + assert result == {"만듦": ["pipe@40.0", "st0"], "지움": [], "못만듦": []} folder = _items(root) / "st0" got = {path.name for path in folder.iterdir()} assert {