-
Notifications
You must be signed in to change notification settings - Fork 46
/
serve-doc
executable file
·37 lines (30 loc) · 892 Bytes
/
serve-doc
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
#!/usr/bin/python
import SimpleHTTPServer
import SocketServer
import os
import sys
path = os.path.dirname(sys.argv[0])
os.chdir(path)
os.chdir('html')
PORT = 17081
HINTS = """
Please browser Ceph docs at:\033[1;32m http://localhost:%s \033[0m
\033[1;31m Ctrl-C\033[0m to stop.
""" % str(PORT)
class ReusingTCPServer(SimpleHTTPServer.SimpleHTTPRequestHandler):
allow_reuse_address = True
def send_head(self):
# horrible kludge because SimpleHTTPServer is buggy wrt
# slash-redirecting of requests with query arguments, and will
# redirect to /foo?q=bar/ -- wrong slash placement
self.path = self.path.split('?', 1)[0]
return SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self)
httpd = SocketServer.TCPServer(
("", PORT),
ReusingTCPServer,
)
try:
print(HINTS)
httpd.serve_forever()
except KeyboardInterrupt:
pass