-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpserver.py
More file actions
74 lines (62 loc) · 2.47 KB
/
Copy pathhttpserver.py
File metadata and controls
74 lines (62 loc) · 2.47 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
# Python 2.7 simple web server that serves a directory that contains a built Vue.js app
# Run this script from the command line with:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import os
import time
import subprocess
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
with open('src/index.html', 'r') as f:
self.wfile.write(f.read())
return
elif self.path == '/packages':
self.send_response(404)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write("Coming Soon")
# Host the /media/p4/Presets/setlists directory
elif self.path == '/media/p4/Presets/setlists':
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
with open('/media/p4/Presets/setlists', 'r') as f:
self.wfile.write(f.read())
return
else:
path = "." + self.path
# Serve the file requested
# Check if the file exists
if os.path.isfile(path):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
with open(path, 'r') as f:
self.wfile.write(f.read())
else:
self.send_response(404)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write('404: File not found')
return
def do_POST(self):
if self.path.split('?')[0] == '/zen':
args = self.path.split('?')[1].split('&')
#print(self.headers)
print("Command: " + str(args[0].split('=')[1]) + " Package: " + str(args[1].split('=')[1]))
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(time.asctime())
return
if __name__ == '__main__':
try:
server = HTTPServer(('0.0.0.0', 5555), MyHandler)
print('Started httpserver on port ' , 5555)
server.serve_forever()
except KeyboardInterrupt:
print('^C received, shutting down the web server')
server.socket.close()