[dpdk-web] [PATCH] serve_local.py: add script to serve locally

Vincent JARDIN vincent.jardin at 6wind.com
Thu Jan 28 15:34:18 CET 2016


Could you write a Dockerfile to test it when updating website? Dockerfile
would run serve_local.py.
Le 28 janv. 2016 14:24, "Harry van Haaren" <harry.van.haaren at intel.com> a
écrit :

> This patch adds a basic Python web server that will serve
> the DPDK site for testing purposes. Basic URL re-writing
> and folder scanning is implementent to make the links work.
>
> Signed-off-by: Harry van Haaren <harry.van.haaren at intel.com>
> ---
>
>  Makefile               |  3 +++
>  scripts/serve_local.py | 58
> ++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 61 insertions(+)
>  create mode 100644 Makefile
>  create mode 100644 scripts/serve_local.py
>
> diff --git a/Makefile b/Makefile
> new file mode 100644
> index 0000000..2a7602a
> --- /dev/null
> +++ b/Makefile
> @@ -0,0 +1,3 @@
> +
> +local:
> +       python scripts/serve_local.py
> diff --git a/scripts/serve_local.py b/scripts/serve_local.py
> new file mode 100644
> index 0000000..ef59474
> --- /dev/null
> +++ b/scripts/serve_local.py
> @@ -0,0 +1,58 @@
> +import BaseHTTPServer
> +from os import curdir, sep, listdir
> +
> +folders = ["./","./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())
> +            f.close()
> +        except IOError:
> +            self.send_error(404,'File Not Found: %s' % path)
> +
> +def run(server_class=BaseHTTPServer.HTTPServer,
> +        handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
> +    server_address = ('', 8000)
> +    httpd = server_class(server_address, handler_class)
> +    httpd.serve_forever()
> +
> +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!")
> --
> 2.5.0
>
>


More information about the web mailing list