From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 0BFE3C45A for ; Thu, 28 Jan 2016 14:24:33 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 28 Jan 2016 05:24:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,358,1449561600"; d="scan'208";a="891045501" Received: from sie-lab-212-120.ir.intel.com (HELO silpixa00394367.ir.intel.com) ([10.237.212.120]) by fmsmga001.fm.intel.com with ESMTP; 28 Jan 2016 05:24:17 -0800 From: Harry van Haaren To: web@dpdk.org Date: Thu, 28 Jan 2016 13:23:42 +0000 Message-Id: <1453987422-22469-1-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.5.0 Subject: [dpdk-web] [PATCH] serve_local.py: add script to serve locally X-BeenThere: web@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: website maintenance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jan 2016 13:24:34 -0000 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 --- 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