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

* Re: [dpdk-web] [PATCH] serve_local.py: add script to serve locally
  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-10 10:01 ` Thomas Monjalon
  1 sibling, 1 reply; 5+ messages in thread
From: Vincent JARDIN @ 2016-01-28 14:34 UTC (permalink / raw)
  To: Harry Van Haaren; +Cc: web

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

* Re: [dpdk-web] [PATCH] serve_local.py: add script to serve locally
  2016-01-28 14:34 ` Vincent JARDIN
@ 2016-01-29 13:22   ` Van Haaren, Harry
  2016-02-01 14:28     ` Vincent JARDIN
  0 siblings, 1 reply; 5+ messages in thread
From: Van Haaren, Harry @ 2016-01-29 13:22 UTC (permalink / raw)
  To: 'Vincent JARDIN'; +Cc: web

> From: Vincent JARDIN 
> Could you write a Dockerfile to test it when updating website?
> Dockerfile would run serve_local.py.


Sorry I don't understand what the purpose would be of using Docker for this?


Currently the script only depends on a standard Python install,
and will serve the git repo files to localhost:8000

Once running, server doesn't need to be restarted, just edit the code,
and F5 in the browser to update changes.


Perhaps I'm missing something obvious :) -Harry


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

* Re: [dpdk-web] [PATCH] serve_local.py: add script to serve locally
  2016-01-29 13:22   ` Van Haaren, Harry
@ 2016-02-01 14:28     ` Vincent JARDIN
  0 siblings, 0 replies; 5+ messages in thread
From: Vincent JARDIN @ 2016-02-01 14:28 UTC (permalink / raw)
  To: Van Haaren, Harry; +Cc: web

On 29/01/2016 14:22, Van Haaren, Harry wrote:
>> From: Vincent JARDIN
>> Could you write a Dockerfile to test it when updating website?
>> Dockerfile would run serve_local.py.
>
>
> Sorry I don't understand what the purpose would be of using Docker for this?

it allows to have the framework to handle the full content of the 
dpdk.org web server, including its html content.

> Perhaps I'm missing something obvious :) -Harry

let's keep it simple for this contribution, it can be another change.

Thank you,

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

* Re: [dpdk-web] [PATCH] serve_local.py: add script to serve locally
  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-02-10 10:01 ` Thomas Monjalon
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Monjalon @ 2016-02-10 10:01 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: web

2016-01-28 13:23, Harry van Haaren:
> 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>

It is very useful!

Applied, thanks

^ 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).