Last active
June 25, 2020 00:17
-
-
Save mmozeiko/be78c48d581261c0b2e56fa38eeb6c26 to your computer and use it in GitHub Desktop.
Create zip file with explicitly setting +x permissions
This file contains 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 | |
import os | |
import os.path | |
import sys | |
from datetime import datetime | |
from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED | |
# which files to make executable | |
EXECUTABLE = [ | |
"exename", | |
"another_exe", | |
] | |
if len(sys.argv) != 2: | |
exit(f"Usage: {sys.argv[0]} <folder>") | |
name = os.path.basename(sys.argv[1]) | |
with ZipFile(name + ".zip", "w") as z: | |
for root, dirs, files in os.walk(sys.argv[1]): | |
for f in files: | |
full = os.path.join(root, f) | |
rel = os.path.relpath(full, os.path.join(sys.argv[1], "..")) | |
print(rel) | |
dt = datetime.fromtimestamp(os.path.getmtime(full)) | |
dt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second) | |
info = ZipInfo(rel, dt) | |
info.create_system = 3 | |
if f in EXECUTABLE: | |
info.external_attr = 0o100755 << 16 | |
else: | |
info.external_attr = 0o100644 << 16 | |
z.writestr(info, open(full, "rb").read(), ZIP_DEFLATED) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment