9 from external
.minify
import (html_minifier
, rcssmin
, rjsmin
)
10 from external
.wheezy
.template
.engine
import Engine
11 from external
.wheezy
.template
.ext
.core
import CoreExtension
12 from external
.wheezy
.template
.loader
import FileLoader
16 return '%s (%s)' % (env
.get('GIT_VERSION'), env
.get('GIT_SHA'))
18 def build_version(out
, env
):
19 out
.write('const char *VERSION = "%s";\n\n' % get_version(env
))
22 """Compress data in one shot and return the compressed string.
23 Optional argument is the compression level, in range of 0-9.
26 with gzip
.GzipFile(fileobj
=buf
, mode
='wb', compresslevel
=9, mtime
=0.0) as f
:
30 def build_html(mainfile
, var
, out
, env
, isTX
=False):
32 loader
=FileLoader(["html"]),
33 extensions
=[CoreExtension("@@")]
35 template
= engine
.get_template(mainfile
)
36 has_sub_ghz
= '-DRADIO_SX127X=1' in env
['BUILD_FLAGS'] or '-DRADIO_LR1121=1' in env
['BUILD_FLAGS']
37 if '-DRADIO_SX128X=1' in env
['BUILD_FLAGS']:
39 elif '-DRADIO_SX127X=1' in env
['BUILD_FLAGS']:
41 elif '-DRADIO_LR1121=1' in env
['BUILD_FLAGS']:
43 if 'ESP8285' in env
['PIOENV']:
47 data
= template
.render({
48 'VERSION': get_version(env
),
49 'PLATFORM': re
.sub("_via_.*", "", env
['PIOENV']),
51 'hasSubGHz': has_sub_ghz
,
55 if mainfile
.endswith('.html'):
56 data
= html_minifier
.html_minify(data
)
57 if mainfile
.endswith('.css'):
58 data
= rcssmin
.cssmin(data
)
59 if mainfile
.endswith('.js'):
60 data
= rjsmin
.jsmin(data
)
61 out
.write('static const char PROGMEM %s[] = {\n' % var
)
62 out
.write(','.join("0x{:02x}".format(c
) for c
in compress(data
.encode('utf-8'))))
65 def build_common(env
, mainfile
, isTX
):
66 fd
, path
= tempfile
.mkstemp()
68 with os
.fdopen(fd
, 'w') as out
:
69 build_version(out
, env
)
70 build_html(mainfile
, "INDEX_HTML", out
, env
, isTX
)
71 build_html("scan.js", "SCAN_JS", out
, env
, isTX
)
72 build_html("mui.js", "MUI_JS", out
, env
)
73 build_html("elrs.css", "ELRS_CSS", out
, env
)
74 build_html("hardware.html", "HARDWARE_HTML", out
, env
, isTX
)
75 build_html("hardware.js", "HARDWARE_JS", out
, env
)
76 build_html("cw.html", "CW_HTML", out
, env
)
77 build_html("cw.js", "CW_JS", out
, env
)
78 build_html("lr1121.html", "LR1121_HTML", out
, env
)
79 build_html("lr1121.js", "LR1121_JS", out
, env
)
82 if not os
.path
.exists("include/WebContent.h") or not filecmp
.cmp(path
, "include/WebContent.h"):
83 shutil
.copyfile(path
, "include/WebContent.h")
86 target_name
= env
['PIOENV'].upper()
87 build_common(env
, "index.html", not '_RX_' in target_name
)