from pathlib import Path
from importlib.machinery import SourceFileLoader
from importlib.util import spec_from_loader,module_from_spec
import hashlib,json,sys
sys.dont_write_bytecode=True
p=Path(sys.argv[1]) if len(sys.argv)>1 else Path(__file__).resolve().parent
lines=(p/'SHA256SUMS.txt').read_text(encoding='utf-8').splitlines()
for line in lines:
 digest,name=line.split('  ',1)
 if Path(name).name!=name or hashlib.sha256((p/name).read_bytes()).hexdigest()!=digest:raise SystemExit('Checksum mismatch:'+name)
loader=SourceFileLoader('frozen_week',str(p/'analyze.py.txt'))
module=module_from_spec(spec_from_loader(loader.name,loader));loader.exec_module(module)
actual=module.analyze(p)
expected=json.loads((p/'results.json').read_text(encoding='utf-8'))
if actual!=expected:raise SystemExit('Recalculated results differ')
print(json.dumps({'verified_files':len(lines),'results_match':True,'total':actual['total'],'deadline_denominator':actual['deadlines']['denominator']}))
