Skip to content

Commit 446eda7

Browse files
committed
Add tar.gz export because zip doesn't store unix permissions apparently
1 parent b169f57 commit 446eda7

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
.vscode
55
**.sln
66
Packaged/
7-
Packaged.zip
7+
Packaged.zip
8+
Packaged.tar.gz

package.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import subprocess
33
import os
44
import shutil
5+
import tarfile
56

67
COPIED_FILES = [".json"]
7-
PACKAGED_DIR = "./Packaged"
8+
PACKAGED_DIR = "Packaged"
89

910
CMD_SCRIPT = "dotnet exec/{NAME}.dll > nul"
1011
SH_SCRIPT = "#!/bin/sh \n dotnet exec/{NAME}.dll"
@@ -53,16 +54,33 @@
5354

5455
for script_data in [(CMD_SCRIPT, "cmd"), (SH_SCRIPT, "sh")]:
5556
file_path = f"{path}/{subdir}.{script_data[1]}"
56-
with open(file_path, "w") as file:
57-
file.write(script_data[0].replace("{NAME}", subdir))
58-
try:
59-
os.chmod(file_path, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU)
60-
except Exception as e:
61-
print(f"Failed to chmod with error: {e}")
57+
with open(file_path, "w") as archive:
58+
archive.write(script_data[0].replace("{NAME}", subdir))
6259

6360
print(f"Finished packaging {subdir}.")
6461

65-
print("Packaged all bots. Now zipping and removing directory...")
62+
print("Packaged all bots. Now archiving and removing directory...")
63+
64+
def tar_perms_filter(tarinfo: tarfile.TarInfo):
65+
if tarinfo.name.endswith(".sh") or tarinfo.isdir():
66+
tarinfo.mode = 0o755
67+
else:
68+
tarinfo.mode = 0o644
69+
70+
return tarinfo
71+
72+
with tarfile.open(f"{PACKAGED_DIR}.tar.gz", "w:gz") as tar:
73+
for dir_path, dir_names, file_names in os.walk(PACKAGED_DIR):
74+
dir_path_relative = os.path.relpath(dir_path, PACKAGED_DIR) # Don't nest everything inside a 'packaged' dir in the archive
75+
dir_path_archive = dir_path_relative.replace(os.path.sep, "/")
76+
if dir_path_relative != ".":
77+
tar.add(dir_path, dir_path_archive, recursive=False, filter=perms_filter)
78+
79+
for file_name in file_names:
80+
file_path = os.path.join(dir_path, file_name)
81+
file_path_archive = f"{dir_path_archive}/{file_name}"
82+
tar.add(file_path, file_path_archive, filter=perms_filter)
83+
6684

6785
shutil.make_archive(PACKAGED_DIR, 'zip', PACKAGED_DIR)
6886
print("Removing.")

0 commit comments

Comments
 (0)