Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-10-29 17:28:48 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-10-29 17:28:48 (GMT)
commit87274fd89f0c127f05cd34ad912b47a185c4b0e3 (patch)
tree45039f905f53640d9f6b7ad9160c879476f54139
parentff2bee3d9b560148472633381f6dd74d2ebf24ba (diff)
Initial bundle registry code
-rw-r--r--sugar/activity/__init__.py7
-rw-r--r--sugar/activity/bundle.py52
-rw-r--r--sugar/activity/bundleregistry.py32
3 files changed, 91 insertions, 0 deletions
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)