From 2bbedf988b39c5af35777954444ba54ceba13ecb Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 12 Jul 2006 22:17:57 +0200 Subject: [PATCH] Fix a bunch of bugs, more cleanups --- shell/ActivityRegistry.py | 4 ++-- shell/Makefile.am | 2 +- shell/Process.py | 10 ++-------- shell/Session.py | 19 ++++++++++++------- shell/Shell.py | 1 + shell/sugar | 14 +++++++------- shell/sugar-activity | 16 ++++++++++++++++ sugar/__installed__.py.in | 1 + sugar/__uninstalled__.py | 1 + sugar/activity/Activity.py | 16 +++------------- sugar/env.py | 3 +++ 11 files changed, 49 insertions(+), 38 deletions(-) create mode 100755 shell/sugar-activity diff --git a/shell/ActivityRegistry.py b/shell/ActivityRegistry.py index 2ddf7677..957d436e 100644 --- a/shell/ActivityRegistry.py +++ b/shell/ActivityRegistry.py @@ -69,8 +69,8 @@ class ActivityRegistry: activity_exec = cp.get('Activity', 'exec') elif cp.has_option('Activity', 'python_module'): python_module = cp.get('Activity', 'python_module') - activity_exec = 'python -m sugar/activity/Activity %s %s' \ - % (activity_id, python_module) + activity_exec = '%s %s %s' % (env.get_activity_runner(), + activity_id, python_module) env.add_to_python_path(directory) else: logging.error('%s must specifiy exec or python_module' % (path)) diff --git a/shell/Makefile.am b/shell/Makefile.am index ff0a4507..c6064b1f 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -1,4 +1,4 @@ -bin_SCRIPTS = sugar +bin_SCRIPTS = sugar sugar-activity sugardir = $(pkgdatadir)/shell sugar_PYTHON = \ diff --git a/shell/Process.py b/shell/Process.py index 5fee9053..ea5dd0c7 100644 --- a/shell/Process.py +++ b/shell/Process.py @@ -6,18 +6,12 @@ class Process: """Object representing one of the session processes""" def __init__(self, command): - self._pid = None self._command = command def get_name(self): return self._command def start(self): - print self._command - logging.debug('Start %s' % (self._command)) - args = self._command.split() - flags = gobject.SPAWN_SEARCH_PATH or gobject.SPAWN_STDERR_TO_DEV_NULL - result = gobject.spawn_async(args, flags=flags, standard_output=True) - self._pid = result[0] - self._stdout = result[2] + flags = gobject.SPAWN_SEARCH_PATH + result = gobject.spawn_async(args, flags=flags) diff --git a/shell/Session.py b/shell/Session.py index 93f4b1fb..2aeb044e 100644 --- a/shell/Session.py +++ b/shell/Session.py @@ -1,9 +1,10 @@ import os import gtk -import sugar.theme +import gobject from Shell import Shell from Process import Process +import sugar.theme class ActivityProcess(Process): def __init__(self, module): @@ -21,8 +22,12 @@ class DbusProcess(Process): return 'Dbus' def start(self): - Process.start(self) - + args = self._command.split() + flags = gobject.SPAWN_SEARCH_PATH + result = gobject.spawn_async(args, flags=flags, standard_output=True, + standard_error=True) + self._stdout = result[2] + dbus_file = os.fdopen(self._stdout) addr = dbus_file.readline() addr = addr.strip() @@ -42,9 +47,6 @@ class Session: def __init__(self): sugar.theme.setup() - self._shell = Shell() - self._shell.start() - def start(self): """Start the session""" process = DbusProcess() @@ -52,8 +54,11 @@ class Session: process = MatchboxProcess() process.start() + + shell = Shell() + shell.start() - registry = self._shell.get_registry() + registry = shell.get_registry() for activity_module in registry.list_activities(): process = ActivityProcess(activity_module) process.start() diff --git a/shell/Shell.py b/shell/Shell.py index 6b30bad3..df75d1fa 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -3,6 +3,7 @@ import os import dbus import gtk import wnck +import gobject from sugar.LogWriter import LogWriter from ConsoleLogger import ConsoleLogger diff --git a/shell/sugar b/shell/sugar index 528aa190..756fe260 100755 --- a/shell/sugar +++ b/shell/sugar @@ -5,8 +5,6 @@ import os import pwd import random -from Emulator import Emulator - def add_to_python_path(path): sys.path.insert(0, path) if os.environ.has_key('PYTHONPATH'): @@ -15,10 +13,6 @@ def add_to_python_path(path): else: os.environ['PYTHONPATH'] = path -# FIXE Don't run the emulator on the OLPC -emulator = Emulator() -emulator.start() - i = 0 for arg in sys.argv: if arg == '--test-user': @@ -46,8 +40,14 @@ else: import sugar.env add_to_python_path(os.path.join(sugar.env.get_data_dir(), 'shell')) print 'Running the installed sugar...' + +from Emulator import Emulator + +# FIXE Don't run the emulator on the OLPC +emulator = Emulator() +emulator.start() -print 'Redirecting output to the console, press Ctrl+Down to open it.' +print 'Redirecting output to the console, press F3 to open it.' from Session import Session diff --git a/shell/sugar-activity b/shell/sugar-activity new file mode 100755 index 00000000..bc6e38af --- /dev/null +++ b/shell/sugar-activity @@ -0,0 +1,16 @@ +#!/usr/bin/python + +import sys + +import gobject + +from sugar.activity import Activity +from sugar.LogWriter import LogWriter +from sugar import theme + +theme.setup() + +lw = LogWriter(sys.argv[1]) +lw.start() + +Activity.register_factory(sys.argv[1], sys.argv[2]) diff --git a/sugar/__installed__.py.in b/sugar/__installed__.py.in index 1b3a64ba..cb8222de 100644 --- a/sugar/__installed__.py.in +++ b/sugar/__installed__.py.in @@ -1,2 +1,3 @@ sugar_data_dir = '@prefix@/share/sugar' +sugar_activity_runner = '@prefix@/bin/sugar-activity' sugar_activities_dir = '@prefix@/share/sugar/activities' diff --git a/sugar/__uninstalled__.py b/sugar/__uninstalled__.py index 6b2e1dd6..be5abb4e 100644 --- a/sugar/__uninstalled__.py +++ b/sugar/__uninstalled__.py @@ -1,4 +1,5 @@ import os sugar_data_dir = os.path.dirname(os.path.dirname(__file__)) +sugar_activity_runner = os.path.join(sugar_data_dir, 'shell/sugar-activity') sugar_activities_dir = os.path.join(sugar_data_dir, 'activities') diff --git a/sugar/activity/Activity.py b/sugar/activity/Activity.py index c0de8e09..2b16f918 100644 --- a/sugar/activity/Activity.py +++ b/sugar/activity/Activity.py @@ -11,7 +11,6 @@ import gtk, gobject from sugar.LogWriter import LogWriter from sugar import keybindings import sugar.util -import sugar.theme SHELL_SERVICE_NAME = "caom.redhat.Sugar.Shell" SHELL_SERVICE_PATH = "/com/redhat/Sugar/Shell" @@ -83,13 +82,8 @@ def create(activity_name, service = None, args = None): else: factory.create() -def main(activity_name, activity_class): - """Starts the activity main loop.""" - sugar.theme.setup() - - log_writer = LogWriter(activity_name) - log_writer.start() - +def register_factory(activity_name, activity_class): + """Register the activity factory.""" factory = ActivityFactory(activity_name, activity_class) gtk.main() @@ -98,8 +92,7 @@ class ActivityDbusService(dbus.service.Object): """Base dbus service object that each Activity uses to export dbus methods. The dbus service is separate from the actual Activity object so that we can - tightly control what stuff passes through print aaaa - the dbus python bindings.""" + tightly control what stuff passes through the dbus python bindings.""" _ALLOWED_CALLBACKS = [ON_PUBLISH_CB] @@ -223,6 +216,3 @@ class Activity(gtk.Window): def publish(self): """Called to request the activity to publish itself on the network.""" pass - -if __name__ == "__main__": - main(sys.argv[1], sys.argv[2]) diff --git a/sugar/env.py b/sugar/env.py index df1fb302..0d2c2498 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -36,3 +36,6 @@ def get_data_dir(): def get_activities_dir(): return sugar_activities_dir + +def get_activity_runner(): + return sugar_activity_runner