mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
[Python] Generate index.html for web flasher
This commit is contained in:
@@ -2,6 +2,7 @@ import argparse
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
import collections
|
||||
|
||||
manifest_binfiles = {}
|
||||
|
||||
@@ -9,15 +10,15 @@ manifest_binfiles = {}
|
||||
def create_arg_parser():
|
||||
# Creates and returns the ArgumentParser object
|
||||
|
||||
parser = argparse.ArgumentParser(description='Description of your app.')
|
||||
parser = argparse.ArgumentParser(description='Generate index.html and manifest JSON files for web flasher.')
|
||||
parser.add_argument('inputDirectory',
|
||||
help='Path to the input directory.')
|
||||
help='Path to the input directory containing ESPEasy .bin files.')
|
||||
parser.add_argument('--outputDirectory',
|
||||
help='Path to the output that contains the resumes.')
|
||||
help='Path to the output that contains the resumes. e.g. --outputDirectory=bin/')
|
||||
return parser
|
||||
|
||||
|
||||
def create_display_text(description, families):
|
||||
def create_display_text(description, version, families):
|
||||
fam_split = []
|
||||
esp32_split = []
|
||||
if 'ESP8266' in families:
|
||||
@@ -42,7 +43,7 @@ def create_display_text(description, families):
|
||||
|
||||
fam_str = ','.join(fam_split)
|
||||
|
||||
return '{} [{}]'.format(description, fam_str)
|
||||
return '{} {} [{}]'.format(version, description, fam_str)
|
||||
|
||||
|
||||
def parse_filename(file, version, variant, file_suffix):
|
||||
@@ -58,6 +59,8 @@ def parse_filename(file, version, variant, file_suffix):
|
||||
sub_group = 'NotSet'
|
||||
flash_size = 'NotSet'
|
||||
|
||||
build_flags = ''
|
||||
|
||||
state = 'Missed'
|
||||
|
||||
if ".factory.bin" in file_suffix:
|
||||
@@ -134,22 +137,30 @@ def parse_filename(file, version, variant, file_suffix):
|
||||
|
||||
if 'NotSet' not in group:
|
||||
sub_group_spit = group.split('_')
|
||||
sub_group_spit.append(flash_size)
|
||||
|
||||
# Add some flags to differentiate the groups
|
||||
# but also use this to sort the items per main group.
|
||||
specials = []
|
||||
specials.append(flash_size)
|
||||
if '_PSRAM' in variant:
|
||||
sub_group_spit.append('PSRAM')
|
||||
specials.append('PSRAM')
|
||||
if 'LittleFS' in variant:
|
||||
sub_group_spit.append('LittleFS')
|
||||
specials.append('LittleFS')
|
||||
if '_IRExt' in variant:
|
||||
sub_group_spit.append('IRExt')
|
||||
specials.append('IRExt')
|
||||
elif '_IR' in variant:
|
||||
sub_group_spit.append('IR')
|
||||
specials.append('IR')
|
||||
if '_VCC' in variant:
|
||||
sub_group_spit.append('VCC')
|
||||
specials.append('VCC')
|
||||
if '_ETH' in variant:
|
||||
sub_group_spit.append('ETH')
|
||||
specials.append('ETH')
|
||||
|
||||
for sp in specials:
|
||||
sub_group_spit.append(sp)
|
||||
|
||||
sub_group = '_'.join(sub_group_spit)
|
||||
description = ' '.join(sub_group_spit)
|
||||
build_flags = '_'.join(specials)
|
||||
|
||||
state = "Group"
|
||||
else:
|
||||
@@ -181,6 +192,7 @@ def parse_filename(file, version, variant, file_suffix):
|
||||
manifest['families'] = families
|
||||
manifest['version'] = version
|
||||
manifest['new_install_prompt_erase'] = True
|
||||
manifest['build_flags'] = build_flags
|
||||
parts = dict([('path', file), ('offset', 0)])
|
||||
if add_improv:
|
||||
builds = dict([('chipFamily', chipFamily), ('improv', False), ('parts', [parts])])
|
||||
@@ -197,8 +209,9 @@ def parse_filename(file, version, variant, file_suffix):
|
||||
manifest_binfiles[main_group][sub_group]['builds'].append(builds)
|
||||
manifest_binfiles[main_group][sub_group]['families'].append(chipFamily)
|
||||
|
||||
display_string = create_display_text(description, manifest_binfiles[main_group][sub_group]['families'])
|
||||
display_string = create_display_text(description, version, manifest_binfiles[main_group][sub_group]['families'])
|
||||
manifest_binfiles[main_group][sub_group]['displaytext'] = display_string
|
||||
manifest_binfiles[main_group][sub_group]['manifestfilename'] = '{}{}'.format(sub_group, manifest_suff)
|
||||
|
||||
|
||||
|
||||
@@ -221,10 +234,128 @@ def list_folder(bin_folder):
|
||||
parse_filename(file, version, variant, file_suffix)
|
||||
|
||||
|
||||
def generate_manifest_files(bin_folder, output_prefix):
|
||||
# options for HTML. Will be sorted based on file order and flags
|
||||
html_options = {}
|
||||
|
||||
# HTML option lines, generated from sorted html_options
|
||||
group_lines = []
|
||||
|
||||
# the main grouping in the combo box on the web flasher page
|
||||
main_group_list = [
|
||||
'4M Flash',
|
||||
'16M Flash',
|
||||
'2M Flash',
|
||||
'1M Flash',
|
||||
'Device Specific',
|
||||
'Custom',
|
||||
'Custom Misc',
|
||||
'Misc']
|
||||
|
||||
for main_group in main_group_list:
|
||||
if main_group in manifest_binfiles:
|
||||
html_options_group = []
|
||||
group_lines.append(' <optgroup label="{}">\n'.format(main_group))
|
||||
for sub_group in manifest_binfiles[main_group]:
|
||||
value = '{}{}'.format(
|
||||
output_prefix,
|
||||
manifest_binfiles[main_group][sub_group]['manifestfilename'])
|
||||
label = manifest_binfiles[main_group][sub_group]['displaytext']
|
||||
build_flags = manifest_binfiles[main_group][sub_group]['build_flags']
|
||||
manifest_file = os.path.join(
|
||||
bin_folder,
|
||||
manifest_binfiles[main_group][sub_group]['manifestfilename']
|
||||
)
|
||||
|
||||
manifest = manifest_binfiles[main_group][sub_group]
|
||||
|
||||
manifest.pop('build_flags')
|
||||
manifest.pop('families')
|
||||
manifest.pop('manifestfilename')
|
||||
|
||||
html_sub_group = dict(
|
||||
[
|
||||
('value', value),
|
||||
('label', label),
|
||||
('flags', build_flags),
|
||||
('manifest_file', manifest_file),
|
||||
('manifest', manifest)
|
||||
]
|
||||
)
|
||||
html_options_group.append(html_sub_group)
|
||||
|
||||
html_options_group_sorted = sorted(html_options_group, key=lambda x: x['flags'])
|
||||
html_options[main_group] = html_options_group_sorted
|
||||
|
||||
for option in html_options_group_sorted:
|
||||
group_lines.append(' <option value="{}" >{}</option>\n'.format(
|
||||
option['value'],
|
||||
option['label']))
|
||||
|
||||
with open(option['manifest_file'], "w") as file:
|
||||
json.dump(option['manifest'], file, indent=4)
|
||||
|
||||
group_lines.append(' </optgroup>\n')
|
||||
|
||||
#print(json.dumps(html_options, indent=2))
|
||||
|
||||
html_out_file = os.path.join(bin_folder, 'index.html')
|
||||
|
||||
with open(html_out_file, "w") as html_file:
|
||||
lines = [
|
||||
'<!DOCTYPE html>\n',
|
||||
'<html>\n',
|
||||
' <head>\n',
|
||||
' <style>\n',
|
||||
' body {\n',
|
||||
' font-family: sans-serif;\n',
|
||||
' }\n',
|
||||
' .pick-variant {\n',
|
||||
' margin-bottom: 16px;\n',
|
||||
' }\n',
|
||||
' </style>\n',
|
||||
' <script\n',
|
||||
' type="module"\n',
|
||||
' src="https://unpkg.com/esp-web-tools@8.0.6/dist/web/install-button.js?module"\n',
|
||||
' ></script>\n',
|
||||
' </head>\n',
|
||||
' <body>\n',
|
||||
' <h1>Install ESPEasy </h1>\n',
|
||||
'\n',
|
||||
' <div class="pick-variant">\n',
|
||||
' <p>\n',
|
||||
' To install ESPEasy, connect your ESP device to your computer, pick your\n',
|
||||
' selected variant and click the install button.\n',
|
||||
' </p>\n',
|
||||
' <select>\n'
|
||||
]
|
||||
|
||||
lines_tail = [
|
||||
' </select>\n',
|
||||
' </div>\n',
|
||||
' <esp-web-install-button></esp-web-install-button>\n',
|
||||
' <script>\n',
|
||||
' const selectEl = document.querySelector(".pick-variant select");\n',
|
||||
' const installEl = document.querySelector("esp-web-install-button");\n',
|
||||
' installEl.manifest = selectEl.value;\n',
|
||||
' selectEl.addEventListener("change", () => {\n',
|
||||
' installEl.manifest = selectEl.value;\n',
|
||||
' });\n',
|
||||
' </script>\n',
|
||||
' </body>\n',
|
||||
'</html>'
|
||||
]
|
||||
|
||||
html_file.writelines(lines)
|
||||
html_file.writelines(group_lines)
|
||||
html_file.writelines(lines_tail)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
arg_parser = create_arg_parser()
|
||||
parsed_args = arg_parser.parse_args(sys.argv[1:])
|
||||
if os.path.exists(parsed_args.inputDirectory):
|
||||
list_folder(parsed_args.inputDirectory)
|
||||
print(json.dumps(manifest_binfiles))
|
||||
generate_manifest_files(parsed_args.inputDirectory, parsed_args.outputDirectory)
|
||||
#print(json.dumps(manifest_binfiles))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user