Skip to content

Commit e92e0d8

Browse files
authored
Merge pull request #4 from TheFlameFish/packaging-reorginization
Packaging Reorganization
2 parents 4745393 + 8806510 commit e92e0d8

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

.gitignore

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

package.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
COPIED_FILES = [".json"]
88
PACKAGED_DIR = "Packaged"
99

10+
ARCHIVE_DIR = "Archives"
11+
1012
CMD_SCRIPT = "dotnet exec/{NAME}.dll > nul"
1113
SH_SCRIPT = "dotnet exec/{NAME}.dll"
1214

@@ -69,19 +71,34 @@ def tar_perms_filter(tarinfo: tarfile.TarInfo):
6971

7072
return tarinfo
7173

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=tar_perms_filter)
74+
def make_archives(directory: str, name: str = None):
75+
if name is None: name = directory.split("/")[-1]
76+
77+
print(f"Archiving {name} with tar.gz")
78+
with tarfile.open(f"{ARCHIVE_DIR}/{name}.tar.gz", "w:gz") as tar:
79+
for dir_path, _dir_names, file_names in os.walk(directory):
80+
dir_path_relative = os.path.relpath(dir_path, directory) # Don't nest everything inside a 'packaged' dir in the archive
81+
dir_path_archive = dir_path_relative.replace(os.path.sep, "/")
82+
if dir_path_relative != ".":
83+
tar.add(dir_path, dir_path_archive, recursive=False, filter=tar_perms_filter)
84+
85+
for file_name in file_names:
86+
file_path = os.path.join(dir_path, file_name)
87+
file_path_archive = f"{dir_path_archive}/{file_name}"
88+
tar.add(file_path, file_path_archive, filter=tar_perms_filter)
89+
90+
print(f"Archiving {name} with zip")
91+
shutil.make_archive(f"{ARCHIVE_DIR}/{name}", 'zip', directory)
92+
93+
if os.path.exists(ARCHIVE_DIR):
94+
# Probably best to clear out the dir so all files are guaranteed up-to-date
95+
shutil.rmtree(ARCHIVE_DIR)
7896

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=tar_perms_filter)
97+
os.mkdir(ARCHIVE_DIR)
8398

99+
make_archives(PACKAGED_DIR, "FlameFishRobocode")
100+
for bot in os.listdir(PACKAGED_DIR):
101+
make_archives(f"{PACKAGED_DIR}/{bot}")
84102

85-
shutil.make_archive(PACKAGED_DIR, 'zip', PACKAGED_DIR)
86103
print("Removing.")
87104
shutil.rmtree(PACKAGED_DIR)

0 commit comments

Comments
 (0)