"""Check an extracted website package (GLB excluded) against WEBSITE_MANIFEST.json. Standard library only."""
from pathlib import Path
from hashlib import sha256
import json
root = Path(__file__).resolve().parent
manifest = json.loads((root / 'WEBSITE_MANIFEST.json').read_text())
for item in manifest['files']:
    data = (root / item['path']).read_bytes()
    assert len(data) == item['bytes'] and sha256(data).hexdigest() == item['sha256'], item['path']
stray = sorted(p.relative_to(root).as_posix() for p in root.rglob('*') if p.is_file() and p.suffix.lower() == '.glb')
assert not stray, 'Unexpected GLB in a website package: ' + ', '.join(stray)
print('PASS: %d files match WEBSITE_MANIFEST.json. Not included: %s.' % (len(manifest['files']), ', '.join(i['path'] for i in manifest['not_included'])))
print('The original manifests in this package still name the GLB; use WEBSITE_MANIFEST.json for this package.')
