-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.py
More file actions
161 lines (129 loc) · 5.5 KB
/
build.py
File metadata and controls
161 lines (129 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import os
import shutil
import zipfile
from datetime import datetime
from pathlib import Path
from circup.commands import main as circup_cli
# each path is a tuple that contains:
# (path within learn repo, directory name to use inside of apps/)
LEARN_PROJECT_PATHS = [
("Metro/Metro_RP2350_Snake/", "Metro_RP2350_Snake"),
("Metro/Metro_RP2350_Memory/memory_game/", "Metro_RP2350_Memory"),
("Metro/Metro_RP2350_CircuitPython_Matrix/", "Metro_RP2350_CircuitPython_Matrix"),
("Metro/Metro_RP2350_FlappyNyanCat/", "Metro_RP2350_FlappyNyanCat"),
("Metro/Metro_RP2350_Match3/match3_game/", "Metro_RP2350_Match3"),
("Fruit_Jam/FruitJam_Breakout/", "FruitJam_Breakout"),
("Metro/Metro_RP2350_Chips_Challenge/", "Metro_RP2350_Chips_Challenge"),
("Metro/Metro_RP2350_Minesweeper/", "Metro_RP2350_Minesweeper"),
("Fruit_Jam/Larsio_Paint_Music/", "Larsio_Paint_Music"),
("Fruit_Jam/Fruit_Jam_IRC_Client/", "Fruit_Jam_IRC_Client"),
("Fruit_Jam/Fruit_Jam_PyPaint/", "Fruit_Jam_PyPaint"),
("Fruit_Jam/Fruit_Jam_Spell_Jam/", "Fruit_Jam_Spell_Jam"),
("Fruit_Jam/Fruit_Jam_Logic_Gates/", "Fruit_Jam_Logic_Gates"),
]
def create_font_specific_zip(
font_path: Path, src_dir: Path, learn_projects_dir: Path, output_dir: Path
):
# Get font name without extension
font_name = font_path.stem
# Create output zip filename
output_zip = output_dir / f"fruit_jam_{font_name}.zip"
# Create a clean temporary directory for building the zip
temp_dir = output_dir / "temp"
if temp_dir.exists():
shutil.rmtree(temp_dir)
temp_dir.mkdir(parents=True)
try:
# Copy src contents
shutil.copytree(src_dir, temp_dir, dirs_exist_ok=True)
# remove empty __init__.py file
os.remove(temp_dir / "__init__.py")
# Create fonts directory and copy the specific font
fonts_dir = temp_dir / "fonts"
fonts_dir.mkdir(parents=True, exist_ok=True)
shutil.copy2(font_path, fonts_dir / "terminal.lvfontbin")
# Extract learn-projects contents into apps directory
apps_dir = temp_dir / "apps"
apps_dir.mkdir(parents=True, exist_ok=True)
# copy learn apps
for learn_app_path, dir_name in LEARN_PROJECT_PATHS:
shutil.copytree(
f"Adafruit_Learning_System_Guides/{learn_app_path}",
apps_dir / dir_name,
dirs_exist_ok=True,
)
# copy builtin apps
shutil.copytree("builtin_apps", apps_dir, dirs_exist_ok=True)
shutil.copyfile("mock_boot_out.txt", temp_dir / "boot_out.txt")
libcache_dir = output_dir / "libcache"
lib_dir = temp_dir / "lib"
if libcache_dir.exists():
lib_dir.mkdir(parents=True, exist_ok=True)
shutil.copytree(libcache_dir, lib_dir, dirs_exist_ok=True)
else:
# install launcher required libs
circup_cli(["--path", temp_dir, "install", "--auto"], standalone_mode=False)
# install apps required libs
for app_dir in os.listdir(apps_dir):
circup_cli(
[
"--path",
temp_dir,
"install",
"--auto",
"--auto-file",
f"apps/{app_dir}/code.py",
],
standalone_mode=False,
)
# create libcache dir
libcache_dir.mkdir(parents=True)
# copy the installed libs from temp_dir to cache
shutil.copytree(lib_dir, libcache_dir, dirs_exist_ok=True)
os.remove(temp_dir / "boot_out.txt")
# Create the final zip file
with zipfile.ZipFile(output_zip, "w", zipfile.ZIP_DEFLATED) as zf:
for file_path in temp_dir.rglob("*"):
if file_path.is_file():
modification_time = datetime(2000, 1, 1, 0, 0, 0)
modification_timestamp = modification_time.timestamp()
os.utime(file_path, (modification_timestamp, modification_timestamp))
arcname = file_path.relative_to(temp_dir)
zf.write(file_path, arcname)
print(f"Created {output_zip}")
finally:
# Clean up temporary directory
shutil.rmtree(temp_dir, ignore_errors=True)
def download_learn_projects():
try:
shutil.rmtree("Adafruit_Learning_System_Guides/")
except FileNotFoundError:
pass
os.system("git clone https://github.com/adafruit/Adafruit_Learning_System_Guides.git")
def main():
# download all learn project zips
download_learn_projects()
# Get the project root directory
root_dir = Path(__file__).parent
# Set up paths
fonts_dir = root_dir / "fonts"
src_dir = root_dir / "src"
learn_projects_dir = root_dir / "learn-projects"
output_dir = root_dir / "dist"
# Create a cache directory for downloaded libs
libcache_dir = output_dir / "libcache"
if libcache_dir.exists():
shutil.rmtree(libcache_dir)
# delete output dir if it exists
if output_dir.exists():
shutil.rmtree(output_dir)
# Create output directory
output_dir.mkdir(parents=True, exist_ok=True)
# Process each font
for font_path in fonts_dir.glob("*.lvfontbin"):
create_font_specific_zip(font_path, src_dir, learn_projects_dir, output_dir)
# delete libcache dir if it exists
if libcache_dir.exists():
shutil.rmtree(libcache_dir)
if __name__ == "__main__":
main()