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 data
= template
.render({
37 'VERSION': get_version(env
),
38 'PLATFORM': re
.sub("_via_.*", "", env
['PIOENV']),
40 'sx127x': '-DRADIO_SX127X=1' in env
['BUILD_FLAGS']
42 if mainfile
.endswith('.html'):
43 data
= html_minifier
.html_minify(data
)
44 if mainfile
.endswith('.css'):
45 data
= rcssmin
.cssmin(data
)
46 if mainfile
.endswith('.js'):
47 data
= rjsmin
.jsmin(data
)
48 out
.write('static const char PROGMEM %s[] = {\n' % var
)
49 out
.write(','.join("0x{:02x}".format(c
) for c
in compress(data
.encode('utf-8'))))
52 def build_common(env
, mainfile
, isTX
):
53 fd
, path
= tempfile
.mkstemp()
55 with os
.fdopen(fd
, 'w') as out
:
56 build_version(out
, env
)
57 build_html(mainfile
, "INDEX_HTML", out
, env
, isTX
)
58 build_html("scan.js", "SCAN_JS", out
, env
, isTX
)
59 build_html("mui.js", "MUI_JS", out
, env
)
60 build_html("elrs.css", "ELRS_CSS", out
, env
)
61 build_html("hardware.html", "HARDWARE_HTML", out
, env
, isTX
)
62 build_html("hardware.js", "HARDWARE_JS", out
, env
)
63 build_html("cw.html", "CW_HTML", out
, env
)
64 build_html("cw.js", "CW_JS", out
, env
)
67 if not os
.path
.exists("include/WebContent.h") or not filecmp
.cmp(path
, "include/WebContent.h"):
68 shutil
.copyfile(path
, "include/WebContent.h")
71 target_name
= env
['PIOENV'].upper()
72 build_common(env
, "index.html", not '_RX_' in target_name
)