Skip to content

Commit b10139c

Browse files
committed
add code to generate pdez files for all examples
1 parent d9ff749 commit b10139c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

build/examples.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import filecmp
44
import os
55
import subprocess
6+
import zipfile
67

78
# script to keep the examples in sync [fry 210808]
89

@@ -16,6 +17,8 @@
1617
# contains Basic Examples, Topic Examples
1718
P4_DOCS_REPO = os.path.realpath('../../processing-other/website/content/examples')
1819

20+
PDEZ_PATH = os.path.realpath('examples-pdez')
21+
1922

2023
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2124

@@ -69,6 +72,45 @@ def handle(examples_folder, web_folder):
6972
print(f'{status} {rel_path}')
7073

7174

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+
72113
if __name__ == "__main__":
73114
handle(f'{EXAMPLES_DIR}/Basics', f'{P4_DOCS_REPO}/Basic Examples')
74115
handle(f'{EXAMPLES_DIR}/Topics', f'{P4_DOCS_REPO}/Topic Examples')
116+
# examples_to_pdez(EXAMPLES_DIR, PDEZ_PATH)

0 commit comments

Comments
 (0)