[dpdk-web] [PATCH 3/3] local: open in a browser

Thomas Monjalon thomas.monjalon at 6wind.com
Wed Feb 10 11:05:06 CET 2016


When starting the local server the URL is printed and automatically open
in the default browser.
A delay is introduced to wait server initialization and avoid an error
page in the browser.

Signed-off-by: Thomas Monjalon <thomas.monjalon at 6wind.com>
---
 scripts/serve_local.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/scripts/serve_local.py b/scripts/serve_local.py
index bf05e86..a0b165d 100644
--- a/scripts/serve_local.py
+++ b/scripts/serve_local.py
@@ -1,6 +1,8 @@
 import BaseHTTPServer
+import threading, subprocess
 from os import curdir, sep, listdir
 
+port = 8000
 folders = [".", "./doc", "./dev"]
 
 html_files = []
@@ -45,10 +47,17 @@ class DPDK_Handler(BaseHTTPServer.BaseHTTPRequestHandler):
 
 def run(server_class=BaseHTTPServer.HTTPServer,
         handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
-    server_address = ('', 8000)
+    server_address = ('', port)
     httpd = server_class(server_address, handler_class)
     httpd.serve_forever()
 
+def open_browser():
+    subprocess.call(["xdg-open", url])
+
+url = "http://localhost:%d" % port
+print(url)
+threading.Timer(1, open_browser).start()
+
 try:
     run(handler_class=DPDK_Handler)
 except BaseHTTPServer.socket.error:
-- 
2.7.0



More information about the web mailing list