-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProduceDefine.py
executable file
·59 lines (37 loc) · 1.14 KB
/
ProduceDefine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
## (c) O. Kolkman 2022
##
import sys
import re
import os.path
import gzip
def bytes_to_c_arr(data):
return [format(b, '#04x') for b in data]
path = sys.argv[1]
print("//Generated from "+path)
_inputname = os.path.basename(path)
p1 = re.compile('-min\.')
filename = p1.sub(".",_inputname)
p2 = re.compile('\.')
_name = p2.sub("_", filename)
try:
_file = open(path, "r")
_data = _file.read()
except:
print("Could not open "+path)
finally:
_file.close()
print("#ifndef WEB"+_name+"_H")
print("#define WEB"+_name+"_H")
print()
# server->on("/EspressoMachine.svg", HTTP_GET, std::bind(&WebInterface::handleEspressoSVG, this, std::placeholders::_1));
#
_compr = gzip.compress(bytes(_data, 'utf-8'))
print("unsigned char "+_name +
"[] = {{{}}};".format(",".join(bytes_to_c_arr(_compr))))
print("unsigned int "+_name+"_len = ", len(_compr), ";")
print("\n\n")
print("#define DEF_HANDLE_"+_name + " server->on(\"/"+filename, end='')
print("\", HTTP_GET, std::bind (&WebInterface::handleFile, this, std::placeholders::_1", end='')
print(",\"" + sys.argv[2]+"\","+_name+","+_name+"_len));")
print("#endif")