Files
MagnetismHeroes/.dryforge/002/execution-support/preserve-previous-final.py
T
2026-10-10 01:27:54 +09:00

36 lines
1.9 KiB
Python

import hashlib
import json
import shutil
from pathlib import Path
from datetime import datetime, timezone
root = Path(__file__).resolve().parents[1]
target = root / 'artifacts/verification/VisualUpgrade/PreviousFinal'
assert not target.exists(), 'PreviousFinal already exists; do not overwrite evidence'
target.mkdir(parents=True)
records = []
for source_dir, name in [(root / 'artifacts/verification/Final', 'verification'),
(root / 'artifacts/android/Final', 'android')]:
for source in sorted(source_dir.rglob('*')):
if not source.is_file():
continue
dest = target / name / source.relative_to(source_dir)
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(source, dest)
actual = hashlib.sha256(dest.read_bytes()).hexdigest()
assert hashlib.sha256(source.read_bytes()).hexdigest() == actual
records.append({'source': source.relative_to(root).as_posix(),
'copy': dest.relative_to(target).as_posix(), 'bytes': dest.stat().st_size, 'sha256': actual})
standard = root / 'artifacts/android/MagnetismHeroes.apk'
if standard.is_file():
dest = target / 'android/standard-MagnetismHeroes.apk'
shutil.copy2(standard, dest)
actual = hashlib.sha256(dest.read_bytes()).hexdigest()
assert actual == hashlib.sha256(standard.read_bytes()).hexdigest()
records.append({'source': standard.relative_to(root).as_posix(), 'copy': dest.relative_to(target).as_posix(),
'bytes': dest.stat().st_size, 'sha256': actual})
assert len(records) > 2500
(target / 'manifest.json').write_text(json.dumps({'status': 'PREVIOUS_RUN_PRESERVED_NOT_CURRENT_VERIFICATION',
'preservedUtc': datetime.now(timezone.utc).isoformat(), 'files': records}, indent=2), encoding='utf-8')
print(f'PREVIOUS_FINAL_PRESERVED files={len(records)} bytes={sum(r["bytes"] for r in records)} sha256_all_matched')