🔒 Repository is read-only – file editing is disabled.

PaganLinux/tmp-check-literal.py main

41 linii Raw ← Powrót
1234567891011121314151617181920212223242526272829303132333435363738394041
#!/usr/bin/env python3
"""Ile docelowych URL-i wystepuje w pliku doslownie (a ile jest lamanych przez YAML)."""
import collections
import json
import os
import re

R = "/var/lib/pagan-sync/recipes"
CONV = ("SAFE_HTTPS", "SAFE_HTTPS_UNVERIFIED")

d = json.load(open("/tmp/https-audit.json"))
occ = [i for c in CONV for i in d.get(c, [])]
print(f"docelowych wystapien: {len(occ)}")

literal = notfound = ambiguous = 0
per_key = collections.Counter()
missing = []
for i in occ:
    p = os.path.join(R, i["recipe"])
    text = open(p, newline="", encoding="utf-8").read()
    raw = i["raw"]
    per_key[i["key"]] += 1
    n = text.count(raw)
    if n == 1:
        literal += 1
    elif n == 0:
        notfound += 1
        missing.append((i["recipe"], i["key"], raw))
    else:
        ambiguous += 1
        missing.append((i["recipe"], i["key"], raw, f"x{n}"))

print(f"  doslownie (1 wystapienie): {literal}")
print(f"  NIE znaleziono doslownie : {notfound}")
print(f"  wiele wystapien          : {ambiguous}")
print("  wg klucza:", dict(per_key))
print()
for m in missing[:40]:
    print("   ", m)
if len(missing) > 40:
    print(f"    ... i {len(missing)-40} wiecej")