DPDK website maintenance
 help / color / mirror / Atom feed
* [dpdk-web] [PATCH] serve_local.py: add script to serve locally
@ 2016-01-28 13:23 Harry van Haaren
  2016-01-28 14:34 ` Vincent JARDIN
  2016-02-10 10:01 ` Thomas Monjalon
  0 siblings, 2 replies; 5+ messages in thread
From: Harry van Haaren @ 2016-01-28 13:23 UTC (permalink / raw)
  To: web

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@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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-02-10 10:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-28 13:23 [dpdk-web] [PATCH] serve_local.py: add script to serve locally Harry van Haaren
2016-01-28 14:34 ` Vincent JARDIN
2016-01-29 13:22   ` Van Haaren, Harry
2016-02-01 14:28     ` Vincent JARDIN
2016-02-10 10:01 ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).