-
Notifications
You must be signed in to change notification settings - Fork 0
/
konko-server
executable file
·48 lines (39 loc) · 1.34 KB
/
konko-server
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
#!/usr/bin/env python
import os
import sys
import CGIHTTPServer, SimpleHTTPServer, BaseHTTPServer
import SocketServer
import kconfig
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
# Hyperlinks with anchors seem to work fine in Microsoft Excel.
# However, they are broken in Apple Numbers. Here is a workaround.
i = self.path.find(u'%23')
if i == -1:
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
else:
p = self.path.replace(u'%23', u'#')
self.send_response(301)
self.send_header(u'Location', self.server.base_url + p)
self.end_headers()
class Server(SocketServer.TCPServer):
allow_reuse_address = True
def main():
param = sys.argv[1:]
if len(param) != 1:
sys.exit(u'usage: {} CONFIGURATION'.format(sys.argv[0]))
config_file, = param
cfg = kconfig.KConfig(config_file)
d = cfg.output_dir
p = cfg.server_port
os.chdir(d)
httpd = Server((u"localhost", p), Handler)
httpd.allow_reuse_address = True
httpd.base_url = u'http://localhost:{}'.format(p)
print u'Server started, hit ctrl-c to stop.'
print u'{} now refers to {}'.format(httpd.base_url, os.getcwdu())
try:
httpd.serve_forever()
except KeyboardInterrupt:
print u'\nStop.'
main()