diff options
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oeqa/utils/httpserver.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/httpserver.py b/meta/lib/oeqa/utils/httpserver.py new file mode 100644 index 0000000000..d4b61547e8 --- /dev/null +++ b/meta/lib/oeqa/utils/httpserver.py | |||
@@ -0,0 +1,32 @@ | |||
1 | import SimpleHTTPServer | ||
2 | import multiprocessing | ||
3 | import os | ||
4 | |||
5 | class HTTPServer(SimpleHTTPServer.BaseHTTPServer.HTTPServer): | ||
6 | |||
7 | def server_start(self, root_dir): | ||
8 | os.chdir(root_dir) | ||
9 | self.serve_forever() | ||
10 | |||
11 | class HTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | ||
12 | |||
13 | def log_message(self, format_str, *args): | ||
14 | pass | ||
15 | |||
16 | class HTTPService(object): | ||
17 | |||
18 | def __init__(self, root_dir): | ||
19 | self.root_dir = root_dir | ||
20 | self.port = 0 | ||
21 | |||
22 | def start(self): | ||
23 | self.server = HTTPServer(('', self.port), HTTPRequestHandler) | ||
24 | if self.port == 0: | ||
25 | self.port = self.server.server_port | ||
26 | self.process = multiprocessing.Process(target=self.server.server_start, args=[self.root_dir]) | ||
27 | self.process.start() | ||
28 | |||
29 | def stop(self): | ||
30 | self.server.server_close() | ||
31 | self.process.terminate() | ||
32 | self.process.join() | ||