diff options
Diffstat (limited to 'meta/lib/oeqa/utils/httpserver.py')
-rw-r--r-- | meta/lib/oeqa/utils/httpserver.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/meta/lib/oeqa/utils/httpserver.py b/meta/lib/oeqa/utils/httpserver.py index 8ce1dd42f4..2aa172bf79 100644 --- a/meta/lib/oeqa/utils/httpserver.py +++ b/meta/lib/oeqa/utils/httpserver.py | |||
@@ -5,9 +5,9 @@ | |||
5 | # | 5 | # |
6 | 6 | ||
7 | import http.server | 7 | import http.server |
8 | import logging | ||
8 | import multiprocessing | 9 | import multiprocessing |
9 | import os | 10 | import os |
10 | import traceback | ||
11 | import signal | 11 | import signal |
12 | from socketserver import ThreadingMixIn | 12 | from socketserver import ThreadingMixIn |
13 | 13 | ||
@@ -15,20 +15,24 @@ class HTTPServer(ThreadingMixIn, http.server.HTTPServer): | |||
15 | 15 | ||
16 | def server_start(self, root_dir, logger): | 16 | def server_start(self, root_dir, logger): |
17 | os.chdir(root_dir) | 17 | os.chdir(root_dir) |
18 | self.logger = logger | ||
18 | self.serve_forever() | 19 | self.serve_forever() |
19 | 20 | ||
20 | class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler): | 21 | class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler): |
21 | 22 | ||
22 | def log_message(self, format_str, *args): | 23 | def log_message(self, format_str, *args): |
23 | pass | 24 | self.server.logger.info(format_str, *args) |
24 | 25 | ||
25 | class HTTPService(object): | 26 | class HTTPService: |
26 | 27 | ||
27 | def __init__(self, root_dir, host='', port=0, logger=None): | 28 | def __init__(self, root_dir, host='', port=0, logger=None): |
28 | self.root_dir = root_dir | 29 | self.root_dir = root_dir |
29 | self.host = host | 30 | self.host = host |
30 | self.port = port | 31 | self.port = port |
31 | self.logger = logger | 32 | if logger: |
33 | self.logger = logger.getChild("HTTPService") | ||
34 | else: | ||
35 | self.logger = logging.getLogger("HTTPService") | ||
32 | 36 | ||
33 | def start(self): | 37 | def start(self): |
34 | if not os.path.exists(self.root_dir): | 38 | if not os.path.exists(self.root_dir): |
@@ -49,7 +53,7 @@ class HTTPService(object): | |||
49 | signal.signal(signal.SIGTERM, orig) | 53 | signal.signal(signal.SIGTERM, orig) |
50 | 54 | ||
51 | if self.logger: | 55 | if self.logger: |
52 | self.logger.info("Started HTTPService on %s:%s" % (self.host, self.port)) | 56 | self.logger.info("Started HTTPService for %s on %s:%s" % (self.root_dir, self.host, self.port)) |
53 | 57 | ||
54 | 58 | ||
55 | def stop(self): | 59 | def stop(self): |
@@ -61,3 +65,10 @@ class HTTPService(object): | |||
61 | if self.logger: | 65 | if self.logger: |
62 | self.logger.info("Stopped HTTPService on %s:%s" % (self.host, self.port)) | 66 | self.logger.info("Stopped HTTPService on %s:%s" % (self.host, self.port)) |
63 | 67 | ||
68 | if __name__ == "__main__": | ||
69 | import sys, logging | ||
70 | |||
71 | logger = logging.getLogger(__name__) | ||
72 | logging.basicConfig(level=logging.DEBUG) | ||
73 | httpd = HTTPService(sys.argv[1], port=8888, logger=logger) | ||
74 | httpd.start() | ||