summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils/httpserver.py
blob: d4b61547e86794f945320f153432136861ffcfb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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()