"""Gera um .tar.gz deterministico (mtime 0, dono 0, ordem alfabetica, gzip sem nome/data). uso: python3 -I pack-source.py ... (cada caminho e arquivo ou pasta sob a raiz)""" import gzip, io, os, sys, tarfile out, root, *paths = sys.argv[1:] files = [] for p in paths: full = os.path.join(root, p) if os.path.isdir(full): for d, _, names in os.walk(full): files += [os.path.relpath(os.path.join(d, n), root) for n in names] else: files.append(p) buf = io.BytesIO() with tarfile.open(fileobj=buf, mode="w", format=tarfile.GNU_FORMAT) as tar: for rel in sorted(set(files)): info = tar.gettarinfo(os.path.join(root, rel), arcname=rel) info.mtime, info.uid, info.gid, info.uname, info.gname = 0, 0, 0, "", "" info.mode = 0o644 with open(os.path.join(root, rel), "rb") as f: tar.addfile(info, f) with open(out, "wb") as raw, gzip.GzipFile(filename="", mode="wb", fileobj=raw, mtime=0, compresslevel=9) as gz: gz.write(buf.getvalue())