|
3 | 3 | import filecmp |
4 | 4 | import os |
5 | 5 | import subprocess |
| 6 | +import zipfile |
6 | 7 |
|
7 | 8 | # script to keep the examples in sync [fry 210808] |
8 | 9 |
|
|
16 | 17 | # contains Basic Examples, Topic Examples |
17 | 18 | P4_DOCS_REPO = os.path.realpath('../../processing-other/website/content/examples') |
18 | 19 |
|
| 20 | +PDEZ_PATH = os.path.realpath('examples-pdez') |
| 21 | + |
19 | 22 |
|
20 | 23 | # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
21 | 24 |
|
@@ -69,6 +72,45 @@ def handle(examples_folder, web_folder): |
69 | 72 | print(f'{status} {rel_path}') |
70 | 73 |
|
71 | 74 |
|
| 75 | +def write_zip(pdez_path, source_folder): |
| 76 | + # print(f'Creating {pdez_path}') |
| 77 | + # print(f' from {source_folder}') |
| 78 | + rel_index = source_folder.rindex('/') + 1 |
| 79 | + zf = zipfile.ZipFile(pdez_path, mode='w') |
| 80 | + try: |
| 81 | + for root, dirs, files in os.walk(source_folder): |
| 82 | + for filename in files: |
| 83 | + path = os.path.join(root, filename) |
| 84 | + internal_path = path[rel_index:] |
| 85 | + # print(internal_path) |
| 86 | + zf.write(path, internal_path, zipfile.ZIP_DEFLATED) |
| 87 | + finally: |
| 88 | + zf.close() |
| 89 | + |
| 90 | + |
| 91 | +def examples_to_pdez(source_folder, target_folder): |
| 92 | + outgoing = set() |
| 93 | + for root, dirs, files in os.walk(source_folder): |
| 94 | + for file in files: |
| 95 | + if file.endswith('.pde'): |
| 96 | + outgoing.add(root[len(source_folder)+1:]) |
| 97 | + |
| 98 | + for item in outgoing: |
| 99 | + print(f'Packaging {item}...') |
| 100 | + # last_slash = item.rfind('/') |
| 101 | + rel_name, sketch_name = item.rsplit('/', 1) |
| 102 | + # parent_path = os.path.join(source_folder) |
| 103 | + category_folder = os.path.join(target_folder, rel_name) |
| 104 | + # print(category_folder) |
| 105 | + if not os.path.exists(category_folder): |
| 106 | + os.makedirs(category_folder) |
| 107 | + |
| 108 | + pdez_path = os.path.join(category_folder, sketch_name + '.pdez') |
| 109 | + # write_zip(pdez_path, source_folder + '/' + item) |
| 110 | + write_zip(pdez_path, source_folder + '/' + item) |
| 111 | + |
| 112 | + |
72 | 113 | if __name__ == "__main__": |
73 | 114 | handle(f'{EXAMPLES_DIR}/Basics', f'{P4_DOCS_REPO}/Basic Examples') |
74 | 115 | handle(f'{EXAMPLES_DIR}/Topics', f'{P4_DOCS_REPO}/Topic Examples') |
| 116 | + # examples_to_pdez(EXAMPLES_DIR, PDEZ_PATH) |
0 commit comments