|
7 | 7 | COPIED_FILES = [".json"] |
8 | 8 | PACKAGED_DIR = "Packaged" |
9 | 9 |
|
| 10 | +ARCHIVE_DIR = "Archives" |
| 11 | + |
10 | 12 | CMD_SCRIPT = "dotnet exec/{NAME}.dll > nul" |
11 | 13 | SH_SCRIPT = "dotnet exec/{NAME}.dll" |
12 | 14 |
|
@@ -69,19 +71,34 @@ def tar_perms_filter(tarinfo: tarfile.TarInfo): |
69 | 71 |
|
70 | 72 | return tarinfo |
71 | 73 |
|
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) |
78 | 96 |
|
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) |
83 | 98 |
|
| 99 | +make_archives(PACKAGED_DIR, "FlameFishRobocode") |
| 100 | +for bot in os.listdir(PACKAGED_DIR): |
| 101 | + make_archives(f"{PACKAGED_DIR}/{bot}") |
84 | 102 |
|
85 | | -shutil.make_archive(PACKAGED_DIR, 'zip', PACKAGED_DIR) |
86 | 103 | print("Removing.") |
87 | 104 | shutil.rmtree(PACKAGED_DIR) |
0 commit comments