|
21 | 21 | } |
22 | 22 |
|
23 | 23 | plugin_path = sys.argv[1]; |
24 | | -output_dir = sys.argv[2] |
| 24 | +plugin_name = sys.argv[2]; |
| 25 | +output_dir = sys.argv[3] |
25 | 26 |
|
26 | 27 | # Utility filesystem functions |
27 | 28 |
|
@@ -83,6 +84,29 @@ def makeArchive(name, root_dir, base_dir): |
83 | 84 | full_path = os.path.join(root_dir, base_dir) |
84 | 85 | tar.add(full_path, arcname=base_dir) |
85 | 86 |
|
| 87 | +def extractWithName(zip_path, output_dir, new_root_name): |
| 88 | + with zipfile.ZipFile(zip_path, 'r') as zip_ref: |
| 89 | + members = zip_ref.namelist() |
| 90 | + top_level = {member.split('/')[0] for member in members if member.strip('/')} |
| 91 | + zip_ref.extractall(output_dir) |
| 92 | + |
| 93 | + new_root_path = os.path.join(output_dir, new_root_name) |
| 94 | + |
| 95 | + if os.path.exists(new_root_path): |
| 96 | + shutil.rmtree(new_root_path) |
| 97 | + |
| 98 | + if len(top_level) == 1 and os.path.isdir(os.path.join(output_dir, list(top_level)[0])): |
| 99 | + # Case 1: Single folder at top level — rename it |
| 100 | + original_root = os.path.join(output_dir, list(top_level)[0]) |
| 101 | + shutil.move(original_root, new_root_path) |
| 102 | + else: |
| 103 | + # Case 2: Multiple top-level items — create new folder and move them in |
| 104 | + os.makedirs(new_root_path, exist_ok=True) |
| 105 | + for name in top_level: |
| 106 | + src_path = os.path.join(output_dir, name) |
| 107 | + dst_path = os.path.join(new_root_path, name) |
| 108 | + shutil.move(src_path, dst_path) |
| 109 | + |
86 | 110 | def split(a, n): |
87 | 111 | k, m = divmod(len(a), n) |
88 | 112 | return (a[i*k+min(i, m):(i+1)*k+min(i+1, m)] for i in range(n)) |
@@ -249,10 +273,9 @@ def generate_binary_data(output_dir, file_list): |
249 | 273 | # copyFile("../../Patches/beat.pd", "./Abstractions") |
250 | 274 |
|
251 | 275 | if os.path.isfile(plugin_path): |
252 | | - with zipfile.ZipFile(plugin_path, 'r') as zip_ref: |
253 | | - zip_ref.extractall(os.path.join(output_dir, "plugdata_version")) |
| 276 | + extractWithName(plugin_path, os.path.join(output_dir, "plugdata_version"), plugin_name) |
254 | 277 | elif os.path.isdir(plugin_path): |
255 | | - copyDir(plugin_path, os.path.join(output_dir, "plugdata_version", os.path.basename(plugin_path))) |
| 278 | + copyDir(plugin_path, os.path.join(output_dir, "plugdata_version", plugin_name)) |
256 | 279 |
|
257 | 280 | makeDir("Extra") |
258 | 281 | copyDir(project_root + "/Libraries/pd-else/Documentation/Extra-files", "Extra/else") |
|
0 commit comments