import datetime, hashlib, json, subprocess
from pathlib import Path
proof=Path('/home/reavus/projects/spt-core/spt-core/.spt/preserved/304-handoff/consumer-linux-7890ead3')
argv=['python3','-u',str(proof/'run-linux-7890ead3.py')]
start=datetime.datetime.now(datetime.timezone.utc).isoformat()
with (proof/'driver.log').open('xb') as log:
    p=subprocess.Popen(argv,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
    for line in p.stdout:
        log.write(line)
        log.flush()
        print(line.decode(errors='replace'),end='',flush=True)
    code=p.wait()
row={'command':argv,'start_utc':start,'end_utc':datetime.datetime.now(datetime.timezone.utc).isoformat(),'native_exit':code,'log_sha256':hashlib.sha256((proof/'driver.log').read_bytes()).hexdigest()}
(proof/'driver-receipt.json').write_text(json.dumps(row,indent=2)+'\n')
print('DRIVER_END '+json.dumps(row),flush=True)
raise SystemExit(code)
