Files
TheTree_mock/docs/plans/original-completion-2026-10-02/execution/drive-offload-old-windows-r09-20261015/thetree-old-windows-r09-retire.py
T

19 lines
3.0 KiB
Python

from pathlib import Path
import json,hashlib,subprocess,shutil
r=Path('/Users/korizatou114/Projects/とりにく工房ゲーム制作部');e=r/'docs/plans/original-completion-2026-10-02/execution/drive-offload-old-windows-r09-20261015';m=json.loads((e/'MANIFEST.json').read_text());v=json.loads((e/'CLOUD_ZIPS_VERIFIED.json').read_text());meta=json.loads((e/'CLOUD_RESTORE_METADATA_VERIFIED.json').read_text());assert v['all_three_whole_zip_bytes_verified']and len(v['files'])==3 and meta['all_restore_bytes_identical']and len(meta['files'])==3
for row in meta['files']:assert hashlib.sha256((e/row['name']).read_bytes()).hexdigest()==row['sha256']
def sha(p):
with p.open('rb')as f:return hashlib.file_digest(f,'sha256').hexdigest()
for x in m['items']:
root=Path(x['source']);assert root.parent==r/'artifacts/original-completion-2026-10-02';check=subprocess.run(['lsof','-nP','+D',str(root/'distribution')],capture_output=True);assert check.returncode==1 and not check.stdout;check=subprocess.run(['lsof','-nP',x['zip']['path']],capture_output=True);assert check.returncode==1 and not check.stdout
assert sha(Path(x['zip']['path']))==x['zip']['sha256'];assert set(str(p.relative_to(root/'distribution'))for p in(root/'distribution').rglob('*')if p.is_file())=={f['relative_path']for f in x['files']}
for f in x['files']:
p=root/'distribution'/f['relative_path'];assert not p.is_symlink();s=p.stat();assert sha(p)==f['sha256']and s.st_size==f['bytes']and s.st_mode&0o777==f['mode']and s.st_mtime_ns==f['mtime_ns']
(e/'SOURCE_RECHECK.json').write_text(json.dumps({'all_three_zip_and_36_distribution_members_exact':True,'no_open_files':True,'cloud_zip_and_restore_byte_verification_complete':True,'formal_credit':0},indent=2)+'\n');before=shutil.disk_usage(r).free;retired=[]
for x in m['items']:
root=Path(x['source']);dist=root/'distribution';hold=root/'.distribution-retiring-r09';assert not hold.exists();dist.rename(hold)
for f in x['files']:(hold/f['relative_path']).unlink()
for p in sorted([p for p in hold.rglob('*')if p.is_dir()],key=lambda p:len(p.parts),reverse=True):p.rmdir()
hold.rmdir();Path(x['zip']['path']).unlink();pointer={'cloud_zip':x['cloud'],'zip_sha256':x['zip']['sha256'],'zip_bytes':x['zip']['bytes'],'source_and_export_proofs_retained_locally':True,'restore_metadata':meta['files'],'local_manifest':str(e/'MANIFEST.json'),'local_restore':str(e/'RESTORE.md'),'same_current_final_Windows_acceptance':False,'formal_credit':0};(root/'CLOUD_WINDOWS_R09.json').write_text(json.dumps(pointer,indent=2)+'\n');retired.append(x['name'])
after=shutil.disk_usage(r).free;result={'retired_packages':retired,'zip_bytes':sum(x['zip']['bytes']for x in m['items']),'distribution_bytes':sum(f['bytes']for x in m['items']for f in x['files']),'free_before':before,'free_after':after,'net_free_delta':after-before,'all_export_proofs_and_sources_retained':True,'all_zip_and_restore_bytes_verified_in_Drive':True,'formal_credit':0};(e/'RETIREMENT.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n');print(json.dumps(result,ensure_ascii=False))