Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2008-05-08 02:32:56 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2008-05-08 02:32:56 (GMT)
commitc2c958a0480ac98c9538af0fe48f94cc9fabbe57 (patch)
tree6740ef70d811c9668ff7a52c48421d624dcad55c
parent1160be18e5addca578cf0c3b503c239400a9cdea (diff)
First pass at the wikiserver activity.
Starts up & displays pages, but code needs to be refactored to improve the shell integration.
-rwxr-xr-xNEWS0
-rw-r--r--activity/activity-web.svg15
-rwxr-xr-xactivity/activity.info6
-rwxr-xr-xbin/launcher3
-rw-r--r--cert8.db1
-rw-r--r--py/launcher.py57
-rw-r--r--py/server.py24
-rwxr-xr-xsetup.py5
8 files changed, 102 insertions, 9 deletions
diff --git a/NEWS b/NEWS
new file mode 100755
index 0000000..e69de29
--- /dev/null
+++ b/NEWS
diff --git a/activity/activity-web.svg b/activity/activity-web.svg
new file mode 100644
index 0000000..c8f466a
--- /dev/null
+++ b/activity/activity-web.svg
@@ -0,0 +1,15 @@
+<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
+ <!ENTITY stroke_color "#010101">
+ <!ENTITY fill_color "#FFFFFF">
+]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="activity-browse">
+ <circle cx="27.375" cy="27.5" display="inline" fill="&fill_color;" r="19.903" stroke="&stroke_color;" stroke-width="3.5"/>
+ <g display="inline">
+ <path d="M27.376,7.598c0,0-11.205,8.394-11.205,19.976 c0,11.583,11.205,19.829,11.205,19.829" fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5"/>
+ <path d="M27.376,7.598c0,0,11.066,9.141,11.066,19.976 c0,10.839-11.066,19.829-11.066,19.829" fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5"/>
+ <line fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5" x1="27.376" x2="27.376" y1="7.598" y2="47.402"/>
+ <line fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5" x1="27.376" x2="27.376" y1="7.598" y2="47.402"/>
+ <line fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5" x1="27.376" x2="27.376" y1="7.598" y2="47.402"/>
+ <line fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5" x1="7.472" x2="47.278" y1="27.5" y2="27.5"/>
+ </g>
+</g></svg>
+
diff --git a/activity/activity.info b/activity/activity.info
new file mode 100755
index 0000000..c410e40
--- /dev/null
+++ b/activity/activity.info
@@ -0,0 +1,6 @@
+[Activity]
+name = Wikipedia
+activity_version = 1
+service_name = org.laptop.WikipediaActivity
+icon = activity-web
+exec = launcher
diff --git a/bin/launcher b/bin/launcher
new file mode 100755
index 0000000..081b234
--- /dev/null
+++ b/bin/launcher
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+exec python $SUGAR_BUNDLE_PATH/py/launcher.py
diff --git a/cert8.db b/cert8.db
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/cert8.db
@@ -0,0 +1 @@
+
diff --git a/py/launcher.py b/py/launcher.py
new file mode 100644
index 0000000..74145ab
--- /dev/null
+++ b/py/launcher.py
@@ -0,0 +1,57 @@
+import os
+import sys
+import signal
+
+from sugar.activity import activityfactory
+from sugar.activity.registry import get_registry
+
+import server
+
+HTTP_PORT = 8000
+WIKIDB = '40ormore.xml.bz2'
+HOME_PAGE = '/wiki/Peru'
+
+def start_server():
+ server.run_server(HTTP_PORT)
+
+def stop_server():
+ sys.exit()
+
+def start_browser():
+ # FIXME:
+ # Launching 'Web' in this way is problematic. It causes a second Browse
+ # activity to appear in the home view, and leaves the Wikipedia
+ # activity in the 'Starting...' state.
+ #
+ # A better solution might be to instantiate the Web activity class into
+ # this process and spawn the server as a child process, rather than the
+ # other way around. In this case we will still need to use the
+ # activityfactory to locate the Web activity bundle directory.
+ activity = get_registry().find_activity('Web')[0]
+
+ extra_args = ['-s', '-u', 'http://localhost:%d%s' % (HTTP_PORT, HOME_PAGE)]
+
+ cmd_args = activityfactory.get_command(activity)
+ cmd_args.extend(extra_args)
+
+ os.execvpe(cmd_args[0], cmd_args, activityfactory.get_environment(activity))
+
+def main():
+ os.chdir(os.environ['SUGAR_BUNDLE_PATH'])
+
+ server.load_db(WIKIDB)
+
+ activity_pid = os.fork()
+
+ if activity_pid:
+ # Kill the server process when the browser process exits.
+ def signal_sigchld(a, b):
+ stop_server()
+ signal.signal(signal.SIGCHLD, signal_sigchld)
+
+ start_server()
+
+ else:
+ start_browser()
+
+if __name__ == '__main__': main()
diff --git a/py/server.py b/py/server.py
index ade7d72..a481b87 100644
--- a/py/server.py
+++ b/py/server.py
@@ -1,6 +1,8 @@
#
# Web server script for Wikiserver project.
#
+# Usage: server.py <dbfile> <port>
+#
# TODO
#
# + Send content in the right charset.
@@ -30,7 +32,7 @@ class WikiRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
s.wfile.write("<html><head><title>%s</title></head>" % title)
s.wfile.write("<body>")
- instaview_src = open('../js/instaview.js').read()
+ instaview_src = open('js/instaview.js').read()
s.wfile.write("<script type='text/javascript'>%s</script>" % instaview_src)
article_text = unicode(wp.wp_load_article(title), 'utf8')
@@ -75,13 +77,17 @@ class WikiRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
s.send_response(404)
-dbname = sys.argv[1]
+def load_db(dbname):
+ wp.wp_load_dump(
+ dbname + '.processed',
+ dbname + '.locate.db',
+ dbname + '.locate.prefixdb',
+ dbname + '.blocks.db')
-wp.wp_load_dump(
- dbname + '.processed',
- dbname + '.locate.db',
- dbname + '.locate.prefixdb',
- dbname + '.blocks.db')
+def run_server(port):
+ httpd = BaseHTTPServer.HTTPServer(('', port), WikiRequestHandler)
+ httpd.serve_forever()
-httpd = BaseHTTPServer.HTTPServer(('', 8000), WikiRequestHandler)
-httpd.serve_forever()
+if __name__ == '__main__':
+ load_db(sys.argv[1])
+ run_server(int(sys.argv[1]))
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..f8b0c89
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+from sugar.activity import bundlebuilder
+
+bundlebuilder.start('Wikipedia')
+