Datasets:
File size: 4,058 Bytes
870b85a 3f15e9f 870b85a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | """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()
|