33 lines
2.4 KiB
Python
33 lines
2.4 KiB
Python
"""Preserve recovered original CAD sources inside this project, read-only externally."""
|
|
from pathlib import Path
|
|
import hashlib,json,shutil,zipfile
|
|
from build_sample_grounds import ROOT,OUTPUT,save
|
|
|
|
destination=ROOT/'data/input/samples_20261102/recovered';destination.mkdir(parents=True,exist_ok=True)
|
|
design=Path('D:/Desktop/업무/01.프로젝트/DR/001 도면-DR/04 DR거더 실시설계도면')
|
|
originals={4:design/'03 목동교/01 공통/@서울-세종 9공구 1000현황.dwg',
|
|
6:design/'05 계문철교/01.공통사항/XREF/서수평장1-현황+선형+노리-20200410.dwg'}
|
|
records=[]
|
|
for number,source in originals.items():
|
|
target=destination/f'{number:02d}_{source.name}';shutil.copyfile(source,target)
|
|
records.append(dict(samples=[number] if number==4 else [6,7],source=str(source),local=str(target),
|
|
sha256=hashlib.sha256(target.read_bytes()).hexdigest(),role='original_missing_XREF'))
|
|
indices=json.loads((OUTPUT/'source_archive_index.json').read_text(encoding='utf-8'))
|
|
for number,index in zip((3,5),indices):
|
|
selected=[entry for entry in index['files'] if entry['name'].endswith('/Merge_5000.dwg')]
|
|
with zipfile.ZipFile(index['archive']) as archive:
|
|
for item in selected:
|
|
variant=('converted_5000' if '/5000/' in item['name'] else 'converted_project') if '/ConvertCoords/' in item['name'] else 'original'
|
|
target=destination/f'{number:02d}_project_topography_{variant}.dwg'
|
|
content=archive.read(item['entry'])
|
|
if any(r['local']==str(target) for r in records):
|
|
if target.read_bytes()!=content:raise ValueError('Different originals share one source role; inspect before choosing')
|
|
continue
|
|
target.write_bytes(content)
|
|
records.append(dict(samples=[number],source=index['archive'],archive_entry=item['name'],local=str(target),
|
|
sha256=hashlib.sha256(target.read_bytes()).hexdigest(),role='original_project_topographic_CAD',variant=variant))
|
|
metadata=[dict(entry=i.filename,bytes=i.file_size) for i in archive.infolist() if i.filename.lower().endswith(('.prj','.xml','.wld','.tfw')) and i.file_size<2_000_000]
|
|
save(OUTPUT/f'{number:02d}_archive_metadata_index.json',metadata)
|
|
save(destination/'source_manifest.json',records)
|
|
for record in records:print(record['samples'],record['role'],Path(record['local']).name,flush=True)
|