Patchwork [08/21] lib/oeqa/utils: new file: httpserver.py useful for serving files over HTTP to the target

login
register
mail settings
Submitter Stanacar, StefanX
Date Aug. 23, 2013, 3:30 p.m.
Message ID <597abc373b744fcf3d5ba84b339078f076a38e9d.1377269485.git.stefanx.stanacar@intel.com>
Download mbox | patch
Permalink /patch/56383/
State Accepted
Commit e38e18d6923cc3db50b56fa3fc64081fe4aa8669
Headers show

Comments

Stanacar, StefanX - Aug. 23, 2013, 3:30 p.m.
From: Mihai Lindner <mihaix.lindner@linux.intel.com>

It can be used by smart repo/channel tests to serve deploy_dir.

Signed-off-by: Mihai Lindner <mihaix.lindner@linux.intel.com>
Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
---
 meta/lib/oeqa/utils/httpserver.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 meta/lib/oeqa/utils/httpserver.py

Patch

diff --git a/meta/lib/oeqa/utils/httpserver.py b/meta/lib/oeqa/utils/httpserver.py
new file mode 100644
index 0000000..d4b6154
--- /dev/null
+++ b/meta/lib/oeqa/utils/httpserver.py
@@ -0,0 +1,32 @@ 
+import SimpleHTTPServer
+import multiprocessing
+import os
+
+class HTTPServer(SimpleHTTPServer.BaseHTTPServer.HTTPServer):
+
+    def server_start(self, root_dir):
+        os.chdir(root_dir)
+        self.serve_forever()
+
+class HTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
+
+    def log_message(self, format_str, *args):
+        pass
+
+class HTTPService(object):
+
+    def __init__(self, root_dir):
+        self.root_dir = root_dir
+        self.port = 0
+
+    def start(self):
+        self.server = HTTPServer(('', self.port), HTTPRequestHandler)
+        if self.port == 0:
+            self.port = self.server.server_port
+        self.process = multiprocessing.Process(target=self.server.server_start, args=[self.root_dir])
+        self.process.start()
+
+    def stop(self):
+        self.server.server_close()
+        self.process.terminate()
+        self.process.join()