28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
"""Compare page graphs (hash-insensitive) of two builds: python pbtn_graph_check.py LIVE_DIST OTHER_DIST"""
|
|
import re, sys
|
|
from pathlib import Path
|
|
|
|
REF = re.compile(r'[A-Za-z0-9_.-]+?-[A-Za-z0-9_-]{8}\.(?:js|css)')
|
|
unhash = lambda name: re.sub(r'-[A-Za-z0-9_-]{8}(?=\.(js|css)$)', '', name)
|
|
BUILD_TIME = re.compile(r'buildTime:`[^`]*`|Date Created: \d{4}-\d{2}-\d{2}')
|
|
|
|
|
|
def graph(root):
|
|
root = Path(root)
|
|
names = {p.name: p.relative_to(root).as_posix() for p in root.rglob('*') if p.is_file()}
|
|
seen, todo = {}, ['index.html']
|
|
while todo:
|
|
rel = todo.pop()
|
|
if rel in seen:
|
|
continue
|
|
seen[rel] = (root / rel).read_text(encoding='utf-8', errors='replace')
|
|
todo += [names[m] for m in REF.findall(seen[rel]) if m in names and names[m] not in seen]
|
|
return {unhash(rel): REF.sub(lambda m: unhash(m.group(0)), text) for rel, text in seen.items()}
|
|
|
|
|
|
a, b = graph(sys.argv[1]), graph(sys.argv[2])
|
|
print('only in first:', sorted(set(a) - set(b)))
|
|
print('only in second:', sorted(set(b) - set(a)))
|
|
changed = sorted(k for k in set(a) & set(b) if BUILD_TIME.sub('', a[k]) != BUILD_TIME.sub('', b[k]))
|
|
print('changed:', changed)
|