sava-telephony / scripts /check_release.py
matthiastl's picture
SAVA fine-tuned for phone lines: PyTorch, ONNX and 8-bit ONNX, with tests and scripts
547c405
Raw History Blame Contribute Delete
1.82 kB
"""Refuse to publish a folder that names this machine or its user.
Scans every file's bytes, model files included: an ONNX export once carried the exporting
machine's source paths in per-node metadata. Looks for this machine's home path, user name and
host name, any absolute home-style path, and any extra words given.
python check_release.py release-telephony --also some-word another-word
"""
from __future__ import annotations
import argparse
import getpass
import re
import socket
import sys
from pathlib import Path
def findings(folder: Path, extra: list[str]) -> list[str]:
host = socket.gethostname().split(".")[0]
words = {str(Path.home()), getpass.getuser(), *extra} | ({host} if len(host) > 3 else set())
pattern = re.compile(
b"|".join([re.escape(word.encode()) for word in sorted(words)] + [rb"/Users/[A-Za-z0-9._-]+", rb"/home/[A-Za-z0-9._-]+", rb"[A-Za-z]:\\Users\\"]),
re.IGNORECASE,
)
found = []
for path in sorted(p for p in folder.rglob("*") if p.is_file()):
matches = pattern.findall(path.read_bytes())
if matches:
found.append(f"{path}: {len(matches)} matches, e.g. {matches[0][:40]!r}")
return found
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("folder", type=Path)
parser.add_argument("--also", nargs="*", default=[], help="more words that must not appear")
args = parser.parse_args()
found = findings(args.folder, args.also)
files = sum(1 for p in args.folder.rglob("*") if p.is_file())
if found:
print("\n".join(found))
sys.exit(f"{len(found)} of {files} files name this machine or its user: do not publish")
print(f"{files} files scanned, nothing found")
if __name__ == "__main__":
main()