11import subprocess , os , shutil , json
22
33CYD_PORTS = [
4- "esp32-3248S035C" ,
54 "esp32-2432S028R" ,
5+ "esp32-3248S035C" ,
66 "esp32-2432S032C-SD" ,
77 "esp32-8048S043C-SD" ,
88 "esp32-8048S043C-SD-alt" ,
2525
2626BASE_DIR = os .getcwd ()
2727
28- def get_manifest (base_path : str , device_name : str ):
28+ def get_manifest (base_path : str , device_name : str , is_s3 : bool ):
2929 return {
3030 "name" : f"to { device_name } " ,
3131 "funding_url" : "https://ko-fi.com/suchmememanyskill" ,
3232 "new_install_prompt_erase" : True ,
3333 "builds" : [
3434 {
35- "chipFamily" : "ESP32-S3" if device_name in ESP_S3_CHIPS else "ESP32" ,
35+ "chipFamily" : "ESP32-S3" if is_s3 else "ESP32" ,
3636 "parts" : [
3737 {
3838 "path" : f"{ base_path } /bootloader.bin" ,
39- "offset" : 0 if device_name in ESP_S3_CHIPS else 0x1000
39+ "offset" : 0 if is_s3 else 0x1000
4040 },
4141 {
4242 "path" : f"{ base_path } /partitions.bin" ,
@@ -61,6 +61,7 @@ def extract_commit() -> str:
6161
6262repo_version = extract_commit ()
6363configurations = []
64+ site_sections : dict [str , dict ] = {"CYD" : []}
6465
6566def add_configuration (board : str ):
6667 configurations .append ({
@@ -69,10 +70,32 @@ def add_configuration(board : str):
6970 "URL" : f"https://suchmememanyskill.github.io/CYD-Klipper/out/{ board } /firmware.bin"
7071 })
7172
73+ def add_site_section (port : str , data : dict [str , bool | str ]):
74+ brand = data ["brand" ] if "brand" in data else "CYD"
75+
76+ if brand not in site_sections :
77+ site_sections [brand ] = []
78+
79+ site_sections [brand ].append ({
80+ "name" : data ["name" ],
81+ "port" : port ,
82+ "default" : "default" in data and data ["default" ],
83+ })
84+
7285if os .path .exists ("out" ):
7386 shutil .rmtree ("out" )
7487
75- for port in CYD_PORTS :
88+ if not os .path .exists ("_site" ):
89+ os .makedirs ("_site" )
90+
91+ with open ("./ci.json" , "r" ) as fp :
92+ ci_data : dict [str , dict [str , bool | str ]] = json .load (fp )
93+
94+ for port , data in ci_data .items ():
95+ if "skip" in data and data ["skip" ]:
96+ print (f"Skipping { port } ..." )
97+ continue
98+
7699 port_path = f"out/{ port } "
77100 os .chdir (BASE_DIR )
78101 os .makedirs (port_path , exist_ok = True )
@@ -84,18 +107,21 @@ def add_configuration(board : str):
84107
85108 shutil .copy (os .path .join (os .path .expanduser ("~" ), ".platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin" ), f"{ port_path } /boot_app0.bin" )
86109 os .chdir (port_path )
87- if (port in ESP_S3_CHIPS ):
88- subprocess .run (["python3" , "-m" , " esptool" , "--chip" , "esp32s3" , "merge_bin" , "-o" , "merged_firmware.bin" , "--flash_mode" , "dio" , "--flash_freq" , "80m" , "--flash_size" , "16MB" , "0x0000" , "bootloader.bin" , "0x8000" , "partitions.bin" , "0xe000" , "boot_app0.bin" , "0x10000" , "firmware.bin" ], check = True )
110+ if (bool ( data [ "s3" ]) ):
111+ subprocess .run (["esptool" , "--chip" , "esp32s3" , "merge_bin" , "-o" , "merged_firmware.bin" , "--flash_mode" , "dio" , "--flash_freq" , "80m" , "--flash_size" , "16MB" , "0x0000" , "bootloader.bin" , "0x8000" , "partitions.bin" , "0xe000" , "boot_app0.bin" , "0x10000" , "firmware.bin" ], check = True )
89112 else :
90- subprocess .run (["python3" , "-m" , " esptool" , "--chip" , "esp32" , "merge_bin" , "-o" , "merged_firmware.bin" , "--flash_mode" , "dio" , "--flash_freq" , "40m" , "--flash_size" , "4MB" , "0x1000" , "bootloader.bin" , "0x8000" , "partitions.bin" , "0xe000" , "boot_app0.bin" , "0x10000" , "firmware.bin" ], check = True )
113+ subprocess .run (["esptool" , "--chip" , "esp32" , "merge_bin" , "-o" , "merged_firmware.bin" , "--flash_mode" , "dio" , "--flash_freq" , "40m" , "--flash_size" , "4MB" , "0x1000" , "bootloader.bin" , "0x8000" , "partitions.bin" , "0xe000" , "boot_app0.bin" , "0x10000" , "firmware.bin" ], check = True )
91114
92115 os .chdir (BASE_DIR )
93116
94117 with open (f"./_site/{ port } .json" , "w" ) as f :
95- json .dump (get_manifest (port_path , port ), f )
118+ json .dump (get_manifest (port_path , port , bool ( data [ "s3" ]) ), f )
96119
97120 add_configuration (port )
98121
122+ if "site" in data and data ["site" ]:
123+ add_site_section (port , data )
124+
99125os .chdir (BASE_DIR )
100126out_dir = "./_site/out"
101127if os .path .exists (out_dir ):
@@ -104,3 +130,16 @@ def add_configuration(board : str):
104130
105131with open ("./_site/OTA.json" , "w" ) as f :
106132 json .dump ({"Configurations" : configurations }, f )
133+
134+ with open ("./_site/index.html" , "w" ) as fp :
135+ with open ("./template.html" , "r" ) as template_fp :
136+ template = template_fp .read ()
137+
138+ insert_html = ""
139+
140+ for brand , sections in site_sections .items ():
141+ option_htmls = [f"<option { 'selected' if x ['default' ] else '' } value=\" { x ['port' ]} \" >{ x ['name' ]} </option>" for x in sections ]
142+ section_html = f"<optgroup label=\" { brand } \" >{ '' .join (option_htmls )} </optgroup>"
143+ insert_html += section_html
144+
145+ fp .write (template .replace ("{{%PORTS%}}" , insert_html ))
0 commit comments