mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-24 13:26:58 +02:00
* created new API functions
* bound html through ajax to parse setup page (not finished now) * added compression option for static html to python module * removed generated h-file from index (redundant information), they will be created on compile time
This commit is contained in:
parent
2556197509
commit
13c88b3626
13 changed files with 347 additions and 213 deletions
|
@ -1,7 +1,8 @@
|
|||
import re
|
||||
import os
|
||||
import gzip
|
||||
|
||||
def convert2Header(inFile):
|
||||
def convert2Header(inFile, compress):
|
||||
fileType = inFile.split(".")[1]
|
||||
define = inFile.split(".")[0].upper()
|
||||
define2 = inFile.split(".")[1].upper()
|
||||
|
@ -17,25 +18,42 @@ def convert2Header(inFile):
|
|||
f = open(inFile, "r")
|
||||
data = f.read().replace('\n', '')
|
||||
f.close()
|
||||
if fileType == "html":
|
||||
if False == compress:
|
||||
if fileType == "html":
|
||||
data = re.sub(r"\>\s+\<", '><', data) # whitespaces between xml tags
|
||||
data = re.sub(r"(\;|\}|\>|\{)\s+", r'\1', data) # whitespaces inner javascript
|
||||
length = len(data) # get unescaped length
|
||||
data = re.sub(r"\"", '\\\"', data) # escape quotation marks
|
||||
else:
|
||||
data = re.sub(r"(\;|\}|\:|\{)\s+", r'\1', data) # whitespaces inner css
|
||||
length = len(data) # get unescaped length
|
||||
else:
|
||||
data = re.sub(r"\>\s+\<", '><', data) # whitespaces between xml tags
|
||||
data = re.sub(r"(\;|\}|\>|\{)\s+", r'\1', data) # whitespaces inner javascript
|
||||
length = len(data) # get unescaped length
|
||||
data = re.sub(r"\"", '\\\"', data) # escape quotation marks
|
||||
else:
|
||||
data = re.sub(r"(\;|\}|\:|\{)\s+", r'\1', data) # whitespaces inner css
|
||||
length = len(data) # get unescaped length
|
||||
|
||||
f = open(outName, "w")
|
||||
f.write("#ifndef __{}_{}_H__\n".format(define, define2))
|
||||
f.write("#define __{}_{}_H__\n".format(define, define2))
|
||||
f.write("const char {}[] PROGMEM = \"{}\";\n".format(inFileVarName, data))
|
||||
f.write("const uint32_t {}_len = {};\n".format(inFileVarName, length))
|
||||
if compress:
|
||||
zipped = gzip.compress(bytes(data, 'utf-8'))
|
||||
zippedStr = ""
|
||||
for i in range(len(zipped)):
|
||||
zippedStr += "0x{:02x}".format(zipped[i]) #hex(zipped[i])
|
||||
if (i + 1) != len(zipped):
|
||||
zippedStr += ", "
|
||||
if (i + 1) % 16 == 0 and i != 0:
|
||||
zippedStr += "\n"
|
||||
f.write("#define {}_len {}\n".format(inFileVarName, len(zipped)))
|
||||
f.write("const uint8_t {}[] PROGMEM = {{\n{}}};\n".format(inFileVarName, zippedStr))
|
||||
else:
|
||||
f.write("const char {}[] PROGMEM = \"{}\";\n".format(inFileVarName, data))
|
||||
f.write("const uint32_t {}_len = {};\n".format(inFileVarName, length))
|
||||
f.write("#endif /*__{}_{}_H__*/\n".format(define, define2))
|
||||
f.close()
|
||||
|
||||
convert2Header("index.html")
|
||||
convert2Header("setup.html")
|
||||
convert2Header("visualization.html")
|
||||
convert2Header("update.html")
|
||||
convert2Header("style.css")
|
||||
convert2Header("index.html", False)
|
||||
convert2Header("setup.html", True)
|
||||
convert2Header("visualization.html", False)
|
||||
convert2Header("update.html", False)
|
||||
convert2Header("style.css", False)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue