mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-03 19:21:38 +02:00
improved html and navi, navi is visible even when API dies #660
reduced maximum allowed JSON size for API to 6000Bytes #660 small fix: output command at `prepareDevInformCmd` #692 improved inverter handling for MQTT #671
This commit is contained in:
parent
9ef2df21fa
commit
4f0d365211
21 changed files with 279 additions and 377 deletions
|
@ -2,10 +2,82 @@ import re
|
|||
import os
|
||||
import gzip
|
||||
import glob
|
||||
|
||||
import shutil
|
||||
import pkg_resources
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
from dulwich import porcelain
|
||||
|
||||
def convert2Header(inFile):
|
||||
required_pkgs = {'dulwich'}
|
||||
installed_pkgs = {pkg.key for pkg in pkg_resources.working_set}
|
||||
missing_pkgs = required_pkgs - installed_pkgs
|
||||
|
||||
if missing_pkgs:
|
||||
env.Execute('"$PYTHONEXE" -m pip install dulwich')
|
||||
|
||||
|
||||
def get_git_sha():
|
||||
try:
|
||||
build_version = porcelain.describe('../../../') # refers to the repository root dir
|
||||
except:
|
||||
build_version = "g0000000"
|
||||
|
||||
build_flag = "-D AUTO_GIT_HASH=\\\"" + build_version[1:] + "\\\""
|
||||
#print ("Firmware Revision: " + build_version)
|
||||
return (build_flag)
|
||||
|
||||
def readVersion(path):
|
||||
f = open(path, "r")
|
||||
lines = f.readlines()
|
||||
f.close()
|
||||
|
||||
today = date.today()
|
||||
search = ["_MAJOR", "_MINOR", "_PATCH"]
|
||||
version = today.strftime("%y%m%d") + "_ahoy_"
|
||||
ver = ""
|
||||
for line in lines:
|
||||
if(line.find("VERSION_") != -1):
|
||||
for s in search:
|
||||
p = line.find(s)
|
||||
if(p != -1):
|
||||
version += line[p+13:].rstrip() + "."
|
||||
ver += line[p+13:].rstrip() + "."
|
||||
return ver[:-1]
|
||||
|
||||
def htmlParts(file, header, nav, footer, version):
|
||||
p = "";
|
||||
f = open(file, "r")
|
||||
lines = f.readlines()
|
||||
f.close();
|
||||
|
||||
f = open(header, "r")
|
||||
h = f.read().strip()
|
||||
f.close()
|
||||
|
||||
f = open(nav, "r")
|
||||
n = f.read().strip()
|
||||
f.close()
|
||||
|
||||
f = open(footer, "r")
|
||||
fo = f.read().strip()
|
||||
f.close()
|
||||
|
||||
for line in lines:
|
||||
line = line.replace("{#HTML_HEADER}", h)
|
||||
line = line.replace("{#HTML_NAV}", n)
|
||||
line = line.replace("{#HTML_FOOTER}", fo)
|
||||
p += line
|
||||
|
||||
#placeholders
|
||||
link = '<a target="_blank" href="https://github.com/lumapu/ahoy/commits/' + get_git_sha() + '">GIT SHA: ' + get_git_sha() + ' :: ' + version + '</a>'
|
||||
p = p.replace("{#VERSION}", version)
|
||||
p = p.replace("{#VERSION_GIT}", link)
|
||||
f = open("tmp/" + file, "w")
|
||||
f.write(p);
|
||||
f.close();
|
||||
return p
|
||||
|
||||
def convert2Header(inFile, version):
|
||||
fileType = inFile.split(".")[1]
|
||||
define = inFile.split(".")[0].upper()
|
||||
define2 = inFile.split(".")[1].upper()
|
||||
|
@ -17,14 +89,19 @@ def convert2Header(inFile):
|
|||
Path("html/h").mkdir(exist_ok=True)
|
||||
else:
|
||||
outName = "h/" + inFileVarName + ".h"
|
||||
Path("h").mkdir(exist_ok=True)
|
||||
|
||||
data = ""
|
||||
if fileType == "ico":
|
||||
f = open(inFile, "rb")
|
||||
data = f.read()
|
||||
f.close()
|
||||
else:
|
||||
f = open(inFile, "r")
|
||||
data = f.read()
|
||||
f.close()
|
||||
if fileType == "html":
|
||||
data = htmlParts(inFile, "includes/header.html", "includes/nav.html", "includes/footer.html", version)
|
||||
else:
|
||||
f = open(inFile, "r")
|
||||
data = f.read()
|
||||
f.close()
|
||||
|
||||
if fileType == "css":
|
||||
data = data.replace('\n', '')
|
||||
|
@ -53,13 +130,17 @@ def convert2Header(inFile):
|
|||
f.close()
|
||||
|
||||
# delete all files in the 'h' dir
|
||||
dir = 'h'
|
||||
wd = 'h'
|
||||
if os.getcwd()[-4:] != "html":
|
||||
dir = "web/html/" + dir
|
||||
wd = "web/html/" + wd
|
||||
|
||||
if os.path.exists(dir):
|
||||
for f in os.listdir(dir):
|
||||
os.remove(os.path.join(dir, f))
|
||||
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
|
||||
if os.getcwd()[-4:] != "html":
|
||||
|
@ -69,6 +150,11 @@ 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")
|
||||
version = readVersion("../../defines.h")
|
||||
|
||||
# go throw the array
|
||||
for val in files_grabbed:
|
||||
convert2Header(val)
|
||||
convert2Header(val, version)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue