Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activity.py24
-rwxr-xr-xactivity/activity.info2
-rwxr-xr-xbin/launcher3
-rw-r--r--py/launcher.py57
-rw-r--r--py/server.py2
5 files changed, 26 insertions, 62 deletions
diff --git a/activity.py b/activity.py
new file mode 100644
index 0000000..3cf7db0
--- /dev/null
+++ b/activity.py
@@ -0,0 +1,24 @@
+import os
+import sys
+
+# Import the WebActivity class from the Web activity directory.
+from sugar.activity import registry
+activity_info = registry.get_registry().get_activity('org.laptop.WebActivity')
+sys.path.append(activity_info.path)
+
+import webactivity
+
+# Default settings.
+HTTP_PORT = '8000'
+WIKIDB = '40ormore.xml.bz2'
+HOME_PAGE = '/wiki/Peru'
+
+# Activity class, extends WebActivity.
+class WikipediaActivity(webactivity.WebActivity):
+ def __init__(self, handle):
+ handle.uri = 'http://localhost:%s%s' % (HTTP_PORT, HOME_PAGE)
+
+ webactivity.WebActivity.__init__(self, handle)
+
+ os.chdir(os.environ['SUGAR_BUNDLE_PATH'])
+ os.spawnlp(os.P_NOWAIT, 'python', 'python', 'py/server.py', WIKIDB, HTTP_PORT)
diff --git a/activity/activity.info b/activity/activity.info
index c410e40..1b15519 100755
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -3,4 +3,4 @@ name = Wikipedia
activity_version = 1
service_name = org.laptop.WikipediaActivity
icon = activity-web
-exec = launcher
+exec = sugar-activity activity.WikipediaActivity
diff --git a/bin/launcher b/bin/launcher
deleted file mode 100755
index 081b234..0000000
--- a/bin/launcher
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-exec python $SUGAR_BUNDLE_PATH/py/launcher.py
diff --git a/py/launcher.py b/py/launcher.py
deleted file mode 100644
index 74145ab..0000000
--- a/py/launcher.py
+++ /dev/null
@@ -1,57 +0,0 @@
-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 e70e541..d9f15c8 100644
--- a/py/server.py
+++ b/py/server.py
@@ -96,4 +96,4 @@ def run_server(port):
if __name__ == '__main__':
load_db(sys.argv[1])
- run_server(int(sys.argv[1]))
+ run_server(int(sys.argv[2]))