Skip to content

Commit

Permalink
0.8.90
Browse files Browse the repository at this point in the history
* added preprocessor defines to HTML (from platform.ini) to reduce the HTML in size if modules aren't enabled
* auto build minimal English versions of ESP8266 and ESP32
  • Loading branch information
lumapu committed Mar 4, 2024
1 parent 0d7c67d commit e5c0e8e
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 78 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/compile_development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ jobs:
matrix:
variant:
- esp8266
- esp8266-minimal
- esp8266-prometheus
- esp8285
- esp32-wroom32
- esp32-wroom32-minimal
- esp32-wroom32-prometheus
- esp32-wroom32-ethernet
- esp32-s2-mini
Expand Down
149 changes: 85 additions & 64 deletions scripts/convertHtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,37 @@
from datetime import date
from pathlib import Path
import subprocess
import configparser
Import("env")

import htmlPreprocessorDefines as prepro



def get_build_flags():
config = configparser.ConfigParser()
config.read('platformio.ini')
global build_flags
build_flags = config["env:" + env['PIOENV']]['build_flags'].split('\n')

for i in range(len(build_flags)):
build_flags[i] = build_flags[i][2:]

# translate board
board = config["env:" + env['PIOENV']]['board']
if board == "esp12e" or board == "esp8285":
build_flags.append("ESP8266")
elif board == "lolin_d32":
build_flags.append("ESP32")
elif board == "lolin_s2_mini":
build_flags.append("ESP32")
build_flags.append("ESP32-S2")
elif board == "lolin_c3_mini":
build_flags.append("ESP32")
build_flags.append("ESP32-C3")
elif board == "esp32-s3-devkitc-1":
build_flags.append("ESP32")
build_flags.append("ESP32-S3")

def get_git_sha():
try:
Expand Down Expand Up @@ -50,38 +79,46 @@ def readVersionFull(path):
return version

def htmlParts(file, header, nav, footer, versionPath, lang):
p = "";
f = open(file, "r")
lines = f.readlines()
f.close();

f = open(header, "r")
h = f.read().strip()
h = f.readlines()
f.close()

f = open(nav, "r")
n = f.read().strip()
n = f.readlines()
f.close()

f = open(footer, "r")
fo = f.read().strip()
fo = f.readlines()
f.close()

linesExt = []
for line in lines:
line = line.replace("{#HTML_HEADER}", h)
line = line.replace("{#HTML_NAV}", n)
line = line.replace("{#HTML_FOOTER}", fo)
p += line
if line.find("{#HTML_HEADER}") != -1:
linesExt.extend(h)
elif line.find("{#HTML_NAV}") != -1:
linesExt.extend(n)
elif line.find("{#HTML_FOOTER}") != -1:
linesExt.extend(fo)
else:
linesExt.append(line)

linesMod = prepro.conv(linesExt, build_flags)

#placeholders
version = readVersion(versionPath);
link = '<a target="_blank" href="https://github.com/lumapu/ahoy/commits/' + get_git_sha() + '">GIT SHA: ' + get_git_sha() + ' :: ' + version + '</a>'
p = ""
for line in linesMod:
p += line

p = p.replace("{#VERSION}", version)
p = p.replace("{#VERSION_FULL}", readVersionFull(versionPath))
p = p.replace("{#VERSION_GIT}", link)

# remove if - endif ESP32
p = checkIf(p)
p = translate(file, p, lang)
p = translate("general", p, lang) # menu / header / footer

Expand All @@ -90,30 +127,6 @@ def htmlParts(file, header, nav, footer, versionPath, lang):
f.close();
return p

def checkIf(data):
if (env['PIOENV'][0:5] == "esp32") or env['PIOENV'][0:4] == "open":
data = data.replace("<!--IF_ESP32-->", "")
data = data.replace("<!--ENDIF_ESP32-->", "")
data = data.replace("/*IF_ESP32*/", "")
data = data.replace("/*ENDIF_ESP32*/", "")
else:
while 1:
start = data.find("<!--IF_ESP32-->")
end = data.find("<!--ENDIF_ESP32-->")+18
if -1 == start:
break
else:
data = data[0:start] + data[end:]
while 1:
start = data.find("/*IF_ESP32*/")
end = data.find("/*ENDIF_ESP32*/")+15
if -1 == start:
break
else:
data = data[0:start] + data[end:]

return data

def findLang(file):
with open('../lang.json') as j:
lang = json.load(j)
Expand Down Expand Up @@ -189,33 +202,41 @@ def convert2Header(inFile, versionPath, lang):
f.write("#endif /*__{}_{}_H__*/\n".format(define, define2))
f.close()

# delete all files in the 'h' dir
wd = 'web/html/h'

if os.path.exists(wd):
for f in os.listdir(wd):
os.remove(os.path.join(wd, f))
wd += "/tmp"
if os.path.exists(wd):
for f in os.listdir(wd):
os.remove(os.path.join(wd, f))

# grab all files with following extensions
os.chdir('./web/html')
types = ('*.html', '*.css', '*.js', '*.ico', '*.json') # the tuple of file types
files_grabbed = []
for files in types:
files_grabbed.extend(glob.glob(files))

Path("h").mkdir(exist_ok=True)
Path("tmp").mkdir(exist_ok=True) # created to check if webpages are valid with all replacements
shutil.copyfile("style.css", "tmp/style.css")

# get language from environment
lang = "en"
if env['PIOENV'][-3:] == "-de":
lang = "de"

# go throw the array
for val in files_grabbed:
convert2Header(val, "../../defines.h", lang)

def main():
get_build_flags()

# delete all files in the 'h' dir
wd = 'web/html/h'

if os.path.exists(wd):
for f in os.listdir(wd):
os.remove(os.path.join(wd, f))
wd += "/tmp"
if os.path.exists(wd):
for f in os.listdir(wd):
os.remove(os.path.join(wd, f))

# grab all files with following extensions
os.chdir('./web/html')
types = ('*.html', '*.css', '*.js', '*.ico', '*.json') # the tuple of file types
files_grabbed = []
for files in types:
files_grabbed.extend(glob.glob(files))

Path("h").mkdir(exist_ok=True)
Path("tmp").mkdir(exist_ok=True) # created to check if webpages are valid with all replacements
shutil.copyfile("style.css", "tmp/style.css")

# get language from environment
lang = "en"
if env['PIOENV'][-3:] == "-de":
lang = "de"


# go throw the array
for val in files_grabbed:
convert2Header(val, "../../defines.h", lang)


main()
39 changes: 39 additions & 0 deletions scripts/htmlPreprocessorDefines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import re
import os
import queue

def error(msg):
print("ERROR: " + msg)
exit()

def check(inp, lst, pattern):
q = queue.LifoQueue()
out = []
keep = True
for line in inp:
x = re.findall(pattern, line)
if len(x) > 0:
if line.find("ENDIF_") != -1:
if q.empty():
error("missing open statement!")
if q.get() != x[0]:
error("wrong close statement!")
keep = True
elif line.find("IF_") != -1:
q.put(x[0])
if keep is True:
keep = x[0] in lst
elif line.find("E") != -1:
if q.empty():
error("missing open statement!")
keep = not keep
else:
if keep is True:
out.append(line)

return out

def conv(inp, lst):
print(lst)
out = check(inp, lst, r'\/\*(?:IF_|ELS|ENDIF_)([A-Z0-9\-_]+)?\*\/')
return check(out, lst, r'\<\!\-\-(?:IF_|ELS|ENDIF_)([A-Z0-9\-_]+)?\-\-\>')
4 changes: 4 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Development Changes

## 0.8.90 - 2024-03-05
* added preprocessor defines to HTML (from platform.ini) to reduce the HTML in size if modules aren't enabled
* auto build minimal English versions of ESP8266 and ESP32

## 0.8.89 - 2024-03-02
* merge PR: Collection of small fixes #1465
* fix: show esp type on `/history` #1463
Expand Down
2 changes: 1 addition & 1 deletion src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 8
#define VERSION_PATCH 89
#define VERSION_PATCH 90

//-------------------------------------
typedef struct {
Expand Down
4 changes: 2 additions & 2 deletions src/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ monitor_filters =

[env:esp32-wroom32-ethernet]
platform = espressif32
board = esp32dev
board = lolin_d32
lib_deps =
khoih-prog/AsyncWebServer_ESP32_W5500
khoih-prog/AsyncUDP_ESP32_W5500
Expand All @@ -214,7 +214,7 @@ monitor_filters =

[env:esp32-wroom32-ethernet-de]
platform = espressif32
board = esp32dev
board = lolin_d32
lib_deps =
khoih-prog/AsyncWebServer_ESP32_W5500
khoih-prog/AsyncUDP_ESP32_W5500
Expand Down
2 changes: 2 additions & 0 deletions src/web/html/includes/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
</a>
<div id="topnav" class="mobile">
<a id="nav3" class="hide" href="/live?v={#VERSION}">{#NAV_LIVE}</a>
<!--IF_ENABLE_HISTORY-->
<a id="nav11" class="acitve" href="/history?v={#VERSION}">{#NAV_HISTORY}</a>
<!--ENDIF_ENABLE_HISTORY-->
<a id="nav4" class="hide" href="/serial?v={#VERSION}">{#NAV_WEBSERIAL}</a>
<a id="nav5" class="hide" href="/setup?v={#VERSION}">{#NAV_SETTINGS}</a>
<span class="separator"></span>
Expand Down
Loading

0 comments on commit e5c0e8e

Please sign in to comment.