From: Harry van Haaren <harry.van.haaren@intel.com>
To: web@dpdk.org
Subject: [dpdk-web] [PATCH] serve_local.py: add script to serve locally
Date: Thu, 28 Jan 2016 13:23:42 +0000 [thread overview]
Message-ID: <1453987422-22469-1-git-send-email-harry.van.haaren@intel.com> (raw)
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
next reply other threads:[~2016-01-28 13:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-28 13:23 Harry van Haaren [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1453987422-22469-1-git-send-email-harry.van.haaren@intel.com \
--to=harry.van.haaren@intel.com \
--cc=web@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).