8
8
9
9
#Replace this with a different path if you need to...
10
10
base_path = os .path .join (os .getcwd (),".." ,"esp8266" ,"data" )
11
+ base_path = os .path .join (os .getcwd (),"data" )
11
12
12
13
class MyHandler (SimpleHTTPServer .SimpleHTTPRequestHandler ):
13
14
def do_GET (self ):
14
- if self .path .endswith (".tpl" ):
15
+ is_tpl , s = self .process_path (self .path )
16
+ if is_tpl :
15
17
self .send_response (301 )
16
18
self .send_header ("Content-type" , "text/html" )
17
19
self .end_headers ()
18
20
19
- data = self .process_tpl (self . path )
21
+ data = self .process_tpl (s )
20
22
self .wfile .write (data )
21
23
self .wfile .close ()
22
24
return
23
25
SimpleHTTPServer .SimpleHTTPRequestHandler .do_GET (self )
24
26
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
+
25
49
def process_tpl (self ,fn ):
26
50
p = re .compile ('\$(.*?)\$' )
27
51
if fn .startswith ("/" ) or fn .startswith ("\\ " ):
@@ -44,7 +68,7 @@ def process_tpl(self,fn):
44
68
if dd != data :
45
69
data = dd
46
70
tags = p .findall (data )
47
- n = len (tags )
71
+ n_tags = len (tags )
48
72
else :
49
73
i = i + 1
50
74
return data
@@ -72,3 +96,4 @@ def process_tag(self, data, tag, json_dic={}):
72
96
handler = MyHandler
73
97
server = SocketServer .TCPServer (("" ,8080 ), handler )
74
98
server .serve_forever ()
99
+
0 commit comments