Skip to content

Instantly share code, notes, and snippets.

@tsibley
Created February 3, 2025 21:01
Show Gist options
  • Save tsibley/ee1fbadd15eab455405df5ba243a2a2e to your computer and use it in GitHub Desktop.
Save tsibley/ee1fbadd15eab455405df5ba243a2a2e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from copy import copy
from shutil import copyfileobj
from sys import argv, stderr
from zipfile import ZipFile
zi = ZipFile(argv[1], "r")
zo = ZipFile(argv[2], "w")
xform = argv[3]
for zim in zi.infolist():
exec(xform, (ctx := {"m": copy(zim)}))
if (zom := ctx.get("m")):
print("xformed:", zim, "→", zom, file = stderr)
with zi.open(zim, "r") as zif, zo.open(zom, "w") as zof:
copyfileobj(zif, zof)
else:
print("deleted:", zim, file = stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment