From 86bd6f50f0ad5eaaf2110e245c979687eb041d22 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 27 Jul 2006 23:25:08 +0000 Subject: Use dbus activation to launch factories. This breaks p-to-p chat and ./sugar/activities. Will fix tomorrow. --- (limited to 'shell') diff --git a/shell/ActivityRegistry.py b/shell/ActivityRegistry.py index 87f5ea6..3ac8a4f 100644 --- a/shell/ActivityRegistry.py +++ b/shell/ActivityRegistry.py @@ -3,16 +3,13 @@ import os from ConfigParser import ConfigParser from ConfigParser import NoOptionError -from sugar import env - class ActivityModule: """Info about an activity module. Wraps a .activity file.""" - def __init__(self, name, activity_id, activity_exec, directory): + def __init__(self, name, activity_id, directory): self._name = name self._id = activity_id self._directory = directory - self._exec = activity_exec self._show_launcher = False def get_name(self): @@ -23,10 +20,6 @@ class ActivityModule: """Get the activity identifier""" return self._id - def get_exec(self): - """Get the activity executable""" - return self._exec - def get_directory(self): """Get the path to activity directory.""" return self._directory @@ -63,12 +56,9 @@ class ActivityRegistry: def scan_directory(self, path): """Scan a directory for activities and add them to the registry.""" if os.path.isdir(path): - for filename in os.listdir(path): - activity_dir = os.path.join(path, filename) - if os.path.isdir(activity_dir): - for filename in os.listdir(activity_dir): - if filename.endswith(".activity"): - self.add(os.path.join(activity_dir, filename)) + for f in os.listdir(path): + if f.endswith(".activity"): + self.add(os.path.join(path, f)) def add(self, path): """Add an activity to the registry. The path points to a .activity file.""" @@ -94,21 +84,7 @@ class ActivityRegistry: else: default_type = None - if cp.has_option('Activity', 'exec'): - activity_exec = cp.get('Activity', 'exec') - elif cp.has_option('Activity', 'python_module'): - python_module = cp.get('Activity', 'python_module') - python_module = cp.get('Activity', 'python_module') - activity_exec = '%s %s %s' % ('sugar-activity-factory', - activity_id, python_module) - if default_type: - activity_exec += ' ' + default_type - env.add_to_python_path(directory) - else: - logging.error('%s must specifiy exec or python_module' % (path)) - return False - - module = ActivityModule(name, activity_id, activity_exec, directory) + module = ActivityModule(name, activity_id, directory) self._activities.append(module) if cp.has_option('Activity', 'show_launcher'): diff --git a/shell/Session.py b/shell/Session.py index efb2c22..c33e5c9 100644 --- a/shell/Session.py +++ b/shell/Session.py @@ -11,17 +11,12 @@ from Process import Process import sugar.theme import sugar.env -class ActivityProcess(Process): - def __init__(self, module): - Process.__init__(self, module.get_exec()) - self._module = module - - def get_name(self): - return self._module.get_name() - class DbusProcess(Process): def __init__(self): - Process.__init__(self, "dbus-daemon --session --print-address") + config = sugar.env.get_dbus_config() + cmd = "dbus-daemon --print-address --config-file %s" % config + print cmd + Process.__init__(self, cmd) def get_name(self): return 'Dbus' @@ -66,9 +61,9 @@ class PresenceServiceProcess(Process): class Session: """Takes care of running the shell and all the sugar processes""" - - def __init__(self): + def __init__(self, registry): sugar.theme.setup() + self._registry = registry def start(self): """Start the session""" @@ -81,14 +76,9 @@ class Session: process = PresenceServiceProcess() process.start() - shell = Shell() + shell = Shell(self._registry) shell.start() - registry = shell.get_registry() - for activity_module in registry.list_activities(): - process = ActivityProcess(activity_module) - process.start() - try: gtk.main() except KeyboardInterrupt: diff --git a/shell/Shell.py b/shell/Shell.py index 680f94f..ff668f0 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -42,8 +42,9 @@ class ShellDbusService(dbus.service.Object): gobject.idle_add(self.__log_idle, (module_id, message)) class Shell: - def __init__(self): + def __init__(self, registry): self._screen = wnck.screen_get_default() + self._registry = registry def start(self): log_writer = LogWriter("Shell", False) @@ -56,10 +57,6 @@ class Shell: self._owner = ShellOwner() self._owner.announce() - self._registry = ActivityRegistry() - self._registry.scan_directory(env.get_activities_dir()) - self._registry.scan_directory(os.path.join(env.get_user_dir(), 'activities')) - self._home_window = HomeWindow(self) self._home_window.show() diff --git a/shell/sugar b/shell/sugar index 132c2fe..76db034 100755 --- a/shell/sugar +++ b/shell/sugar @@ -4,6 +4,7 @@ import sys import os import pwd import random +import tempfile import pygtk pygtk.require('2.0') @@ -47,10 +48,33 @@ if os.path.isfile(os.path.join(basedir, 'sugar/__uninstalled__.py')): add_to_bin_path(os.path.join(basedir, 'shell')) add_to_python_path(basedir) add_to_python_path(os.path.join(basedir, 'shell')) + add_to_python_path(os.path.join(basedir, 'activities')) + + from sugar import env + from sugar import setup + + activities_dest = os.path.join(tempfile.gettempdir(), 'sugar') + + if not os.path.isdir(activities_dest): + os.mkdir(activities_dest) + else: + # FIXME delete the whole directory + pass + + setup.install_activities(env.get_activities_dir(), activities_dest, + os.path.join(basedir, 'shell/sugar-activity-factory')) else: - import sugar.env - add_to_python_path(os.path.join(sugar.env.get_data_dir(), 'shell')) print 'Running the installed sugar...' + from sugar import env + add_to_python_path(os.path.join(env.get_data_dir(), 'shell')) + add_to_python_path(os.path.join(env.get_data_dir(), 'activities')) + activities_dest = env.get_activities_dir() + +from ActivityRegistry import ActivityRegistry + +registry = ActivityRegistry() +registry.scan_directory(activities_dest) +#registry.scan_directory(os.path.join(env.get_user_dir(), 'activities')) from Emulator import Emulator @@ -62,5 +86,5 @@ print 'Redirecting output to the console, press F3 to open it.' from Session import Session -session = Session() +session = Session(registry) session.start() diff --git a/shell/sugar-activity-factory b/shell/sugar-activity-factory index c29c074..99133c5 100755 --- a/shell/sugar-activity-factory +++ b/shell/sugar-activity-factory @@ -15,8 +15,8 @@ logging.info('Starting activity factory %s' % sys.argv[1]) theme.setup() -lw = LogWriter(sys.argv[1]) -lw.start() +#lw = LogWriter(sys.argv[1]) +#lw.start() if len(sys.argv) == 4: Activity.register_factory(sys.argv[1], sys.argv[2], sys.argv[3]) -- cgit v0.9.1