From 92f37d31da17cb8e19295e62584ee58e88c83a77 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 31 Oct 2006 10:48:45 +0100 Subject: [PATCH] Several fixes, generate the service, add a test bundle --- sugar/activity/bundle.py | 28 ++++++++++++----- sugar/activity/bundleregistry.py | 31 ++++++++++++++++++- .../Test.activity/activity/activity.info | 5 +++ 3 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 tests/bundle/Test.activity/activity/activity.info diff --git a/sugar/activity/bundle.py b/sugar/activity/bundle.py index 07ff544b..286c9797 100644 --- a/sugar/activity/bundle.py +++ b/sugar/activity/bundle.py @@ -13,24 +13,32 @@ class Bundle: cp = ConfigParser() cp.read([info_path]) - if cp.has_option('Activity', 'service_name'): - self._service_name = cp.get('Activity', 'service_name') + section = 'Activity' + + if cp.has_option(section, 'service_name'): + self._service_name = cp.get(section, 'service_name') else: self._valid = False logging.error('%s must specify a service name' % info_path) - if cp.has_option('Activity', 'name'): - self._service_name = cp.get('Activity', 'name') + if cp.has_option(section, 'name'): + self._name = cp.get(section, 'name') else: self._valid = False logging.error('%s must specify a name' % info_path) - if cp.has_option('Activity', 'show_launcher'): - if cp.get('Activity', 'show_launcher') == 'yes': + if cp.has_option(section, 'exec'): + self._exec = cp.get(section, 'exec') + else: + self._valid = False + logging.error('%s must specify an exec' % info_path) + + if cp.has_option(section, 'show_launcher'): + if cp.get(section, 'show_launcher') == 'yes': self._show_launcher = True - if cp.has_option('Activity', 'icon'): - self._icon = cp.get('Activity', 'icon') + if cp.has_option(section, 'icon'): + self._icon = cp.get(section, 'icon') def is_valid(self): return self._valid @@ -47,6 +55,10 @@ class Bundle: """Get the activity icon name""" return self._icon + def get_exec(self): + """Get the command to execute to launch the activity factory""" + 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 804a514d..8ee1a982 100644 --- a/sugar/activity/bundleregistry.py +++ b/sugar/activity/bundleregistry.py @@ -1,13 +1,41 @@ import os +from ConfigParser import ConfigParser from sugar.activity.bundle import Bundle +class _ServiceParser(ConfigParser): + def optionxform(self, option): + return option + +class _ServiceManager(object): + def __init__(self): + self._path = '/tmp/sugar-services' + + if not os.path.isdir(self._path): + os.mkdir(self._path) + + def add(self, bundle): + name = bundle.get_service_name() + + service_cp = _ServiceParser() + + section = 'D-BUS Service' + service_cp.add_section(section) + service_cp.set(section, 'Name', name) + service_cp.set(section, 'Exec', bundle.get_exec()) + + dest = os.path.join(self._path, name + '.service') + fileobject = open(dest, 'w') + service_cp.write(fileobject) + fileobject.close() + class BundleRegistry: """Service that tracks the available activity bundles""" def __init__(self): self._bundles = {} self._search_path = [] + self._service_manager = _ServiceManager() def get_bundle(self, service_name): """Returns an bundle given his service name""" @@ -33,8 +61,9 @@ class BundleRegistry: self._add_bundle(bundle_dir) def _add_bundle(self, bundle_dir): - info_path = os.path.join(bundle_dir, 'activity.info') + info_path = os.path.join(bundle_dir, 'activity', 'activity.info') if os.path.isfile(info_path): bundle = Bundle(info_path) if bundle.is_valid(): self._bundles[bundle.get_service_name()] = bundle + self._service_manager.add(bundle) diff --git a/tests/bundle/Test.activity/activity/activity.info b/tests/bundle/Test.activity/activity/activity.info new file mode 100644 index 00000000..482cd9d2 --- /dev/null +++ b/tests/bundle/Test.activity/activity/activity.info @@ -0,0 +1,5 @@ +[Activity] +name = Test +service_name = org.laptop.Test +icon = activity-sketch +exec = bu