From 87274fd89f0c127f05cd34ad912b47a185c4b0e3 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 29 Oct 2006 17:28:48 +0000 Subject: Initial bundle registry code --- diff --git a/sugar/activity/__init__.py b/sugar/activity/__init__.py index 959c0a1..cc34df2 100644 --- a/sugar/activity/__init__.py +++ b/sugar/activity/__init__.py @@ -16,3 +16,10 @@ def get_default_type(activity_type): splitted_id = activity_type.split('.') splitted_id.reverse() return '_' + '_'.join(splitted_id) + '._udp' + +from sugar.activity.bundleregistry import BundleRegistry + +_bundle_registry = BundleRegistry() + +def get_bundle_registry(): + return _bundle_registry diff --git a/sugar/activity/bundle.py b/sugar/activity/bundle.py new file mode 100644 index 0000000..ddf968f --- /dev/null +++ b/sugar/activity/bundle.py @@ -0,0 +1,52 @@ +import logging +from ConfigParser import ConfigParser + +class Bundle: + """Info about an activity bundle. Wraps the activity.info file.""" + def __init__(self, info_path): + self._name = None + self._icon = None + self._service_name = None + self._show_launcher = False + self._valid = True + + cp = ConfigParser() + cp.read([info_path]) + + if cp.has_option('Activity', 'service_name'): + self._service_name = cp.get('Activity', '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') + 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': + self._show_launcher = True + + if cp.has_option('Activity', 'icon'): + self._icon = cp.get('Activity', 'icon') + + def is_valid(self): + return self._valid + + def get_name(self): + """Get the activity user visible name.""" + return self._name + + def get_service_name(self): + """Get the activity service name""" + return self._id + + def get_icon(self): + """Get the activity icon name""" + return self._icon + + 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 new file mode 100644 index 0000000..f28b681 --- /dev/null +++ b/sugar/activity/bundleregistry.py @@ -0,0 +1,32 @@ +from sugar.activity.bundle import Bundle + +class BundleRegistry: + """Service that tracks the available activity bundles""" + + def __init__(self): + self._bundles = {} + self._search_path = [] + + def get_bundle(self, service_name): + """Returns an bundle given his service name""" + if self._bundles.has_key(service_name): + return self._bundles[service_name] + else: + return None + + def append_search_path(self, path): + """Append a directory to the bundles search path""" + self._search_path.append(path) + self._scan_directory(path) + + def __iter__(self): + return self._bundles.values() + + def _scan_directory(self, path): + for bundle_dir in os.listdir(path): + if os.path.isdir(bundle_dir): + info_path = os.path.join(bundle_dir, activity_info) + if os.path.isfile(info_path): + bundle = Bundle(info_path) + if bundle.is_valid(): + self._bundles.append(bundle) -- cgit v0.9.1