Skip to content

Commit 518fb0f

Browse files
committed
Added correct handling of the menu links
1 parent 8320040 commit 518fb0f

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

tools/server.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,44 @@
88

99
#Replace this with a different path if you need to...
1010
base_path = os.path.join(os.getcwd(),"..","esp8266","data")
11+
base_path = os.path.join(os.getcwd(),"data")
1112

1213
class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
1314
def do_GET(self):
14-
if self.path.endswith(".tpl"):
15+
is_tpl, s = self.process_path(self.path)
16+
if is_tpl:
1517
self.send_response(301)
1618
self.send_header("Content-type", "text/html")
1719
self.end_headers()
1820

19-
data = self.process_tpl(self.path)
21+
data = self.process_tpl(s)
2022
self.wfile.write(data)
2123
self.wfile.close()
2224
return
2325
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
2426

27+
def process_path(self,s):
28+
#A template link is all caps and is associated to a lower().tpl file in base_path
29+
if s == "/":
30+
return True,"home.tpl"
31+
32+
ret = False,""
33+
s = s.replace("/","")
34+
if s.endswith(".tpl"):
35+
return True,s
36+
37+
s = s.lower()+".tpl"
38+
39+
#these do not exactly match, so let's make them!
40+
s = s.replace("configsta","config_sta")
41+
s = s.replace("configap","config_ap")
42+
s = s.replace("configsys","system")
43+
44+
if os.path.exists(os.path.join(base_path,s)):
45+
ret = True,s
46+
47+
return ret
48+
2549
def process_tpl(self,fn):
2650
p = re.compile('\$(.*?)\$')
2751
if fn.startswith("/") or fn.startswith("\\"):
@@ -44,7 +68,7 @@ def process_tpl(self,fn):
4468
if dd != data:
4569
data = dd
4670
tags = p.findall(data)
47-
n = len(tags)
71+
n_tags = len(tags)
4872
else:
4973
i = i+1
5074
return data
@@ -72,3 +96,4 @@ def process_tag(self, data, tag, json_dic={}):
7296
handler = MyHandler
7397
server = SocketServer.TCPServer(("",8080), handler)
7498
server.serve_forever()
99+

0 commit comments

Comments
 (0)