From 02f375b7108037b6a1dc2f002f03091aa4853b8a Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 22 Feb 2007 15:46:13 +0100 Subject: [PATCH] Add a class attribute as per the updated spec. Cleanups. --- sugar/activity/activityfactoryservice.py | 14 ++++++++++---- sugar/activity/bundle.py | 20 +++++++++++++++++--- sugar/activity/bundleregistry.py | 9 ++------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/sugar/activity/activityfactoryservice.py b/sugar/activity/activityfactoryservice.py index 303d1994..822bf99d 100644 --- a/sugar/activity/activityfactoryservice.py +++ b/sugar/activity/activityfactoryservice.py @@ -17,6 +17,7 @@ import os import sys +from optparse import OptionParser import gobject import gtk @@ -77,15 +78,20 @@ class ActivityFactoryService(dbus.service.Object): def run(args): """Start the activity factory.""" - sys.path.insert(0, args[2]) + parser = OptionParser() + parser.add_option("-p", "--bundle-path", dest="bundle_path", + help="path to the activity bundle") + (options, args) = parser.parse_args() - bundle = Bundle(args[2]) + sys.path.insert(0, options.bundle_path) + + bundle = Bundle(options.bundle_path) logger.start(bundle.get_name()) - os.environ['SUGAR_BUNDLE_PATH'] = args[2] + os.environ['SUGAR_BUNDLE_PATH'] = options.bundle_path os.environ['SUGAR_BUNDLE_SERVICE_NAME'] = bundle.get_service_name() os.environ['SUGAR_BUNDLE_DEFAULT_TYPE'] = bundle.get_default_type() - factory = ActivityFactoryService(bundle.get_service_name(), args[1]) + factory = ActivityFactoryService(bundle.get_service_name(), args[0]) gtk.main() diff --git a/sugar/activity/bundle.py b/sugar/activity/bundle.py index 8c17958a..6a6ebdd7 100644 --- a/sugar/activity/bundle.py +++ b/sugar/activity/bundle.py @@ -1,8 +1,11 @@ import logging import os - from ConfigParser import ConfigParser +from sugar import env + +_PYTHON_FACTORY='sugar-activity-factory' + class Bundle: """Info about an activity bundle. Wraps the activity.info file.""" def __init__(self, path): @@ -38,11 +41,18 @@ class Bundle: self._valid = False logging.error('%s must specify a name' % self._path) - if cp.has_option(section, 'exec'): + if cp.has_option(section, 'class'): + self._class = cp.get(section, 'class') + self._exec = '%s %s --bundle-path=%s' % ( + os.path.join(env.get_shell_bin_dir(), _PYTHON_FACTORY), + self._class, self.get_path()) + elif cp.has_option(section, 'exec'): + self._class = None self._exec = cp.get(section, 'exec') else: + self._exec = None self._valid = False - logging.error('%s must specify an exec' % self._path) + logging.error('%s must specify exec or class' % self._path) if cp.has_option(section, 'show_launcher'): if cp.get(section, 'show_launcher') == 'no': @@ -94,6 +104,10 @@ class Bundle: """Get the command to execute to launch the activity factory""" return self._exec + def get_class(self): + """Get the main Activity class""" + return self._exec + def get_show_launcher(self): """Get whether there should be a visible launcher for the activity""" return self._show_launcher diff --git a/sugar/activity/bundleregistry.py b/sugar/activity/bundleregistry.py index ccf3b794..08f543ff 100644 --- a/sugar/activity/bundleregistry.py +++ b/sugar/activity/bundleregistry.py @@ -11,13 +11,8 @@ class _ServiceManager(object): self._path = env.get_user_service_dir() def add(self, bundle): - name = bundle.get_service_name() - - # FIXME evil hack. Probably need to fix Exec spec - full_exec = env.get_shell_bin_dir() + '/' + bundle.get_exec() - full_exec += ' ' + bundle.get_path() - - util.write_service(name, full_exec, self._path) + util.write_service(bundle.get_service_name(), + bundle.get_exec(), self._path) class BundleRegistry(gobject.GObject): """Service that tracks the available activity bundles"""