16 lines
1.2 KiB
Python
16 lines
1.2 KiB
Python
import re,json,hashlib
|
|
from pathlib import Path
|
|
old=Path('/tmp/progcode-v2-frozen-53f217e5370e');new=Path('/Users/gavrilovdev/tmp/progcode.ru/web/out')
|
|
pages=sorted(p.relative_to(old) for p in old.rglob('*.html'))
|
|
assert set(pages)==set(p.relative_to(new) for p in new.rglob('*.html'))
|
|
def body(path):
|
|
s=path.read_text();s=re.search(r'<body[^>]*>([\s\S]*)</body>',s).group(1)
|
|
return re.sub(r'<script\b[^>]*>[\s\S]*?</script>','',s)
|
|
for p in pages:assert body(old/p)==body(new/p),str(p)
|
|
assets=[p.relative_to(old) for p in old.rglob('*') if p.is_file() and (p.suffix=='.css' or 'visuals' in p.parts)]
|
|
for p in assets:assert (old/p).read_bytes()==(new/p).read_bytes(),str(p)
|
|
h=hashlib.sha256();files=sorted(p.relative_to(new) for p in new.rglob('*') if p.is_file())
|
|
for p in files:h.update(str(p).encode());h.update((new/p).read_bytes())
|
|
report=dict(htmlBodiesCompared=len(pages),htmlBodiesByteIdenticalExcludingScripts=True,routeSetIdentical=True,cssAndMediaByteIdentical=len(assets),sourceHash=json.loads((new/'build-identity.json').read_text())['sourceHash'],buildFiles=len(files),buildHash=h.hexdigest(),baselineSource='53f217e5370ecafe41a0afcfe51fe80f2e443f04637adbe0d4f7476babe9beeb')
|
|
print(json.dumps(report,indent=2))
|