Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Narvaez <dwnarvaez@gmail.com>2013-01-24 13:10:19 (GMT)
committer Daniel Narvaez <dwnarvaez@gmail.com>2013-01-24 13:10:19 (GMT)
commit095746b83f8d4d7ef77cee01b6e62b34c9f90343 (patch)
tree2527b30d9c1857a7d5b9a1aeea03ee6737e34fa9
parent9227fd84f4399b4a1181aed0dc465754c30350e7 (diff)
Basic http server for activities
-rw-r--r--src/jarabe/Makefile.am1
-rw-r--r--src/jarabe/http.py31
-rwxr-xr-xsrc/jarabe/main.py3
3 files changed, 35 insertions, 0 deletions
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():