Datasets:

License:
File size: 1,279 Bytes
9947c3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python3
"""Apply only exact version/hash-matched code overlays; dry-run unless execute."""
import argparse,hashlib,json,subprocess
from pathlib import Path
ROOT=Path(__file__).absolute().parents[1]
def sha(p):return hashlib.sha256(Path(p).read_bytes()).hexdigest()
def main():
 p=argparse.ArgumentParser();p.add_argument('--code-checkout',type=Path,required=True);p.add_argument('--execute',action='store_true');a=p.parse_args();m=json.loads((ROOT/'SOURCE_OVERLAY_MANIFEST.json').read_text())
 revision=subprocess.check_output(['git','-C',str(a.code_checkout),'rev-parse','HEAD'],text=True).strip()
 if revision!=m['revision']:raise ValueError('Checkout revision differs from locked source')
 for r in m['files']:
  target=a.code_checkout/r['path'];source=ROOT/r['patch_file']
  if target.exists() and sha(target)==r['patched_sha256']:continue
  if target.exists() and sha(target)!=r['expected_git_source_sha256']:raise ValueError('Custom source modifications found; refusing to overwrite')
  if not target.exists() and r['expected_git_source_sha256']:raise ValueError('Expected source file is missing')
  print('PLAN',r['path'])
  if a.execute:target.parent.mkdir(parents=True,exist_ok=True);target.write_bytes(source.read_bytes())
if __name__=='__main__':main()