Files
MeltMind/artifacts/phase2-ml-planning-2026-11-17/b9_metadata_inventory.py
T

50 lines
2.7 KiB
Python

"""Four fixed v4 schema reads plus four existing v5 audit receipts; no array decode."""
import hashlib, json, resource, time
from pathlib import Path
from zipfile import ZipFile
from xml.parsers import expat
ROOT=Path(__file__).parent
BASE=ROOT.parent.parent
ARCHIVE=BASE/'artifacts/gre24-v4-reproduction-2026-11-16/data/data.zip'
PREFIXES=['00000666','00000778','00000850','00000890']
resource.setrlimit(resource.RLIMIT_CPU,(120,125))
resource.setrlimit(resource.RLIMIT_AS,(1024**3,1024**3))
start=time.process_time(); wall=time.monotonic(); rows=[]
def sha(p): return hashlib.sha256(p.read_bytes()).hexdigest()
try:
with ZipFile(ARCHIVE) as z:
for prefix in PREFIXES:
name=next(n for n in z.namelist() if n.startswith(prefix+'_') and n.endswith('.vtu'))
info=z.getinfo(name); fields=[]; stack=[]; meta={}
parser=expat.ParserCreate()
def onstart(tag, attrs):
if tag in ('VTKFile','Piece'): meta[tag]=dict(attrs)
if tag=='DataArray': fields.append(dict(association=stack[-1],**attrs))
stack.append(tag)
def onend(tag): stack.pop()
parser.StartElementHandler=onstart; parser.EndElementHandler=onend
# CharacterDataHandler deliberately absent: no base64 or numeric field decode.
with z.open(name) as f:
while True:
if time.monotonic()-wall>240: raise TimeoutError('240s inventory wall cap')
b=f.read(1024**2)
parser.Parse(b,not b)
if not b: break
rows.append(dict(version='v4',member=name,zip_crc32=info.CRC,bytes=info.file_size,
fields=fields,metadata=meta,status='SCHEMA_ONLY_CRC_PASS'))
print('v4',prefix,len(fields),flush=True)
for prefix in PREFIXES:
p=next((BASE/'artifacts/intake-2026-11-13/samples').glob(prefix+'*.audit.json'))
d=json.loads(p.read_text())
rows.append(dict(version='v5',case=d['case'],source=str(p),sha256=sha(p),
fields=d['fields'],series=d['series'],status='REUSED_PRIOR_AUDIT'))
status='COMPLETE_FIXED_4_PLUS_4'
except Exception as e: status='INCOMPLETE'; error=repr(e)
result=dict(status=status,rows=rows,cpu_seconds=time.process_time()-start,
wall_seconds=time.monotonic()-wall,peak_rss_kib=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss,
new_numeric_array_decodes=0,corpus_coverage_claim=False,source_script_sha256=sha(Path(__file__)))
if status=='INCOMPLETE': result['error']=error
(ROOT/'b9-field-schema-inventory.json').write_text(json.dumps(result,indent=2)+'\n')
print(json.dumps({k:v for k,v in result.items() if k!='rows'}),flush=True)