summaryrefslogtreecommitdiff
path: root/scripts/serve_local.py
blob: 589fe48f28b8eb1ee4fc86d8ba4033e6e3360e60 (plain)
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
import BaseHTTPServer
from os import curdir, sep, listdir

port = 8000
folders = [".", "./about", "./doc", "./dev"]

html_files = []

for fol in folders:
    all_files = listdir(fol)
    for f in all_files:
        if f.endswith(".html") and not f.startswith("cgit"):
            html_files.append(f[:len(f)-5])

for f in html_files:
    #print("final files %s" % f)
    pass

class DPDK_Handler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
        mimetype = ""
        if self.path.endswith(".html") or self.path.endswith("/"):
            mimetype='text/html'

        # Rudimental path rewriting to make links work
        path = self.path
        if path == "/":
            path = "index.html"
        else:
            for f in html_files:
                if path.endswith(f) and not path.endswith(".html"):
                    path += ".html"
                    break

        try:
            f = open(curdir + sep + path)
            self.send_response(200)
            self.send_header('Content-type', mimetype)
            self.end_headers()
            self.wfile.write(f.read().replace('//dpdk.org', ''))
            f.close()
        except IOError:
            self.send_error(404, 'File Not Found: %s' % path)
    def log_message(self, format, *args):
        return

def run(server_class=BaseHTTPServer.HTTPServer,
        handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
    server_address = ('', port)
    httpd = server_class(server_address, handler_class)
    httpd.serve_forever()

url = "http://localhost:%d" % port
print(url)
try:
    run(handler_class=DPDK_Handler)
except BaseHTTPServer.socket.error:
    print("#######################################")
    print("#    ERROR: Socket already in use.    #")
    print("# Are you running the server already? #")
    print("#######################################")
except KeyboardInterrupt:
    print("\tQuitting, bye bye!")