-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProduceDefine.py
More file actions
executable file
·74 lines (49 loc) · 1.75 KB
/
ProduceDefine.py
File metadata and controls
executable file
·74 lines (49 loc) · 1.75 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
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:
scope=sys.argv[3]
except IndexError:
scope="class"
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), ";")
if scope=="class":
# print("\n\n")
# print("#define DEF_HANDLE_"+_name + " " + "server->on(\"/"+filename, end='')
# print("\", HTTP_GET, EspressoWebServer::handleFile((AsyncWebServerRequest *) request", end='')
# print(",\"" + sys.argv[2]+"\","+_name+","+_name+"_len));")
print("\n\n")
print("#define DEF_HANDLE_"+_name + " " + "server->on(\"/"+filename, end='')
print("\", HTTP_GET, std::bind (&EspressoWebServer::handleFile, server, std::placeholders::_1", end='')
print(",\"" + sys.argv[2]+"\","+_name+","+_name+"_len));")
else: ### This is serverscope
print("\n\n")
print("#define DEF_HANDLE_"+_name + " " + "on(\"/"+filename, end='')
print("\", HTTP_GET, std::bind (&EspressoWebServer::handleFile, this, std::placeholders::_1", end='')
print(",\"" + sys.argv[2]+"\","+_name+","+_name+"_len));")
print("#endif")