RoboHome / code /robohome /src /apply_admission_patch_v31.py
RoboParty Release
Unify robohome source, assets and scenes delivery
3f15e9f
Raw History Blame Contribute Delete
4.06 kB
"""Install the reviewed admission derivative in this separate v31 engine only."""
import argparse
import hashlib
import json
from pathlib import Path
def sha(path):
return hashlib.sha256(Path(path).read_bytes()).hexdigest()
def save(path, value):
Path(path).write_text(json.dumps(value, ensure_ascii=False, indent=2)+'\n')
def main():
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--apply',action='store_true')
args=parser.parse_args()
root=Path(__file__).resolve().parent;engine=root/'engine'
patches=engine/'native_patches/admission_v31'
receipt=json.loads((patches/'patch_receipt.json').read_text())
inventory=engine/'BASE_SHA256SUMS'
rows=[line.split(' ',1) for line in inventory.read_text().splitlines()]
expected=dict((n,h) for h,n in rows)
if len(rows)!=1343 or len(expected)!=len(rows):raise ValueError('Unexpected parent inventory')
if any(sha(engine/n)!=h for n,h in expected.items()):raise ValueError('Parent native source differs')
changes=[]
for record in receipt['files']:
relative='source/'+record['path'];patch=patches/Path(record['path']).name
if expected.get(relative)!=record['baseline_sha256'] or sha(patch)!=record['patched_sha256']:
raise ValueError('Patch or baseline identity differs: '+relative)
if sha(patches/'base'/patch.name)!=record['baseline_sha256']:
raise ValueError('Preserved parent file differs')
changes.append(dict(path=relative,before=record['baseline_sha256'],after=record['patched_sha256']))
if len(changes)!=3:raise ValueError('Expected exactly three admission files')
if not args.apply:
print(json.dumps(dict(validated=True,applied=False,source_changes=changes)));return
backup=engine/'native_patches/v31_admission_parent'
backup.mkdir(exist_ok=False)
for name in ['BASE_SHA256SUMS','BASE_ORIGIN.json','REPAIR_V2_REVISION.json']:
(backup/name).write_bytes((engine/name).read_bytes())
for record in receipt['files']:
target=engine/'source'/record['path']
target.write_bytes((patches/target.name).read_bytes())
changed={c['path']:c['after'] for c in changes}
inventory.write_text(''.join(changed.get(n,h)+' '+n+'\n' for h,n in rows))
derived=dict(schema='rhg.explicit-derived-release.v1',version='wholehouse-admission-v31-20261030',
parent_backup=str(backup.relative_to(engine)),
parent_manifest_sha256=sha(backup/'REPAIR_V2_REVISION.json'),
parent_inventory_sha256=sha(backup/'BASE_SHA256SUMS'),
parent_origin_sha256=sha(backup/'BASE_ORIGIN.json'),
derived_inventory_sha256=sha(inventory),source_changes=changes,unchanged_source_files=1340,
qualification_claimed=False,scope='source_package_identity_not_scene_or_robot_acceptance')
manifest=json.loads((backup/'REPAIR_V2_REVISION.json').read_text())
manifest.update(version=derived['version'],inventory_sha256=sha(inventory),derived_release=derived)
for change in changes:
manifest.setdefault('implementation_sha256',{})[change['path']]=change['after']
manifest.setdefault('source_changes',{})[change['path']]=dict(before=change['before'],after=change['after'])
save(engine/'REPAIR_V2_REVISION.json',manifest)
save(engine/'BASE_ORIGIN.json',dict(derived,schema='rhg.derived-source-origin.v1',
source_directory='source',base_hash_inventory='BASE_SHA256SUMS',base_files=1343,
derived_source_modified=True,original_inventory_preserved=True,physical_qualification=False,
saved_mesh_checks_required=True))
if any(sha(engine/n)!=changed.get(n,h) for h,n in rows):raise ValueError('Post-install verification failed')
save(engine/'V31_SOURCE_REVISION.json',dict(derived,manifest_sha256=sha(engine/'REPAIR_V2_REVISION.json'),
origin_sha256=sha(engine/'BASE_ORIGIN.json'),source_inventory_verified=True))
print(json.dumps(dict(applied=True,source_changes=changes,native_files_verified=1343)))
if __name__=='__main__':main()