From 095746b83f8d4d7ef77cee01b6e62b34c9f90343 Mon Sep 17 00:00:00 2001 From: Daniel Narvaez Date: Thu, 24 Jan 2013 13:10:19 +0000 Subject: Basic http server for activities --- diff --git a/src/jarabe/Makefile.am b/src/jarabe/Makefile.am index d926d9f..2342bab 100644 --- a/src/jarabe/Makefile.am +++ b/src/jarabe/Makefile.am @@ -11,6 +11,7 @@ SUBDIRS = \ sugardir = $(pythondir)/jarabe sugar_PYTHON = \ __init__.py \ + http.py \ main.py nodist_sugar_PYTHON = config.py diff --git a/src/jarabe/http.py b/src/jarabe/http.py new file mode 100644 index 0000000..3964236 --- /dev/null +++ b/src/jarabe/http.py @@ -0,0 +1,31 @@ +import mimetypes +import threading +import BaseHTTPServer +import os + +from jarabe.model import bundleregistry + +class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): + def do_GET(self): + splitted = self.path.split("/") + bundle_id = splitted[1] + path = splitted[2:] + + registry = bundleregistry.get_registry() + bundle = registry.get_bundle(bundle_id) + + file_path = os.path.join(bundle.get_path(), *path) + with open(file_path) as f: + self.send_response(200) + self.send_header('Content-type', mimetypes.guess_type(file_path)) + self.end_headers() + self.wfile.write(f.read()) + +class ServerThread(threading.Thread): + def run(self): + httpd = BaseHTTPServer.HTTPServer(('', 8000), HTTPRequestHandler) + httpd.serve_forever() + +def start_server(): + thread = ServerThread() + thread.start() diff --git a/src/jarabe/main.py b/src/jarabe/main.py index 44880ba..fa326e1 100755 --- a/src/jarabe/main.py +++ b/src/jarabe/main.py @@ -258,6 +258,9 @@ def main(): sound.restore() keyboard.setup() + from jarabe import http + http.start_server() + sys.path.append(config.ext_path) if not intro.check_profile(): -- cgit v0.9.1