Created
February 3, 2025 21:01
-
-
Save tsibley/ee1fbadd15eab455405df5ba243a2a2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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