Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2007-05-27 18:24:10 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2007-05-27 18:24:10 (GMT)
commit42fef182f4a2853cd7da0c550f77a81c5f749d90 (patch)
tree6366c97d5c324918ce63668f2af4e18c17d835dd /sugar
parent8c70ff2d8647bc6378398aeecf0e8a74a4c5a82c (diff)
Refactor the bundle registry. Move it inside
the shell and expose the parts that should be public to the shell dbus service.
Diffstat (limited to 'sugar')
-rw-r--r--sugar/activity/Makefile.am2
-rw-r--r--sugar/activity/__init__.py14
-rw-r--r--sugar/activity/activity.py6
-rw-r--r--sugar/activity/activityfactory.py3
-rw-r--r--sugar/activity/bundle.py4
-rw-r--r--sugar/activity/bundleregistry.py131
-rw-r--r--sugar/activity/registry.py58
7 files changed, 64 insertions, 154 deletions
diff --git a/sugar/activity/Makefile.am b/sugar/activity/Makefile.am
index d11a347..d6ea9a4 100644
--- a/sugar/activity/Makefile.am
+++ b/sugar/activity/Makefile.am
@@ -8,4 +8,4 @@ sugar_PYTHON = \
activityservice.py \
bundle.py \
bundlebuilder.py \
- bundleregistry.py
+ registry.py
diff --git a/sugar/activity/__init__.py b/sugar/activity/__init__.py
index 524cdfc..84539a3 100644
--- a/sugar/activity/__init__.py
+++ b/sugar/activity/__init__.py
@@ -10,16 +10,7 @@ takes a small dictionary with values corresponding to a
sugar.activity.activityhandle.ActivityHandle
-describing an individual instance of the activity. The
-ActivityFactory service is registered with dbus using the
-global
-
- sugar.activity.bundleregistry.BundleRegistry
-
-service, which creates dbus .service files in a well known
-directory. Those files tell dbus what executable to run
-in order to load the ActivityFactory which will provide
-the creation service.
+describing an individual instance of the activity.
Each activity so registered is described by a
@@ -45,3 +36,6 @@ class. This class allows for querying the ID of the root
window, requesting sharing across the network, and basic
"what type of application are you" queries.
"""
+
+from sugar.activity.registry import ActivityRegistry
+from sugar.activity.registry import ActivityInfo
diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py
index 3dba4c7..dbcbd60 100644
--- a/sugar/activity/activity.py
+++ b/sugar/activity/activity.py
@@ -28,7 +28,6 @@ import gtk, gobject
from sugar.presence import presenceservice
from sugar.activity.activityservice import ActivityService
-from sugar.activity import bundleregistry
from sugar.graphics.window import Window
from sugar.graphics.toolbox import Toolbox
from sugar.graphics.toolbutton import ToolButton
@@ -209,7 +208,6 @@ class Activity(Window, gtk.Container):
self.jobject = datastore.create()
self.jobject['title'] = '%s %s' % (get_bundle_name(), 'Activity')
self.jobject['activity'] = self.get_service_name()
- self.jobject['icon'] = self._get_icon()
self.jobject['keep'] = '0'
self.jobject['buddies'] = ''
self.jobject['preview'] = ''
@@ -332,10 +330,6 @@ class Activity(Window, gtk.Container):
raise
self.destroy()
- def _get_icon(self):
- registry = bundleregistry.get_registry()
- return registry.get_bundle(self.get_service_name()).get_icon()
-
def get_bundle_name():
"""Return the bundle name for the current process' bundle
"""
diff --git a/sugar/activity/activityfactory.py b/sugar/activity/activityfactory.py
index f9c3d6f..809a74d 100644
--- a/sugar/activity/activityfactory.py
+++ b/sugar/activity/activityfactory.py
@@ -89,8 +89,7 @@ class ActivityCreationHandler(gobject.GObject):
The specific service which creates new instances of this
particular type of activity is created during the activity
- registration process in
- sugar.activity.bundleregistry.BundleRegistry which creates
+ registration process in shell bundle registry which creates
service definition files for each registered bundle type.
"""
gobject.GObject.__init__(self)
diff --git a/sugar/activity/bundle.py b/sugar/activity/bundle.py
index 1ef30dd..9410f24 100644
--- a/sugar/activity/bundle.py
+++ b/sugar/activity/bundle.py
@@ -151,10 +151,6 @@ class Bundle:
"""Get the activity service name"""
return self._service_name
- def get_object_path(self):
- """Get the path to the service object"""
- return '/' + self._service_name.replace('.', '/')
-
def get_icon(self):
"""Get the activity icon name"""
return self._icon
diff --git a/sugar/activity/bundleregistry.py b/sugar/activity/bundleregistry.py
deleted file mode 100644
index 0cad4b2..0000000
--- a/sugar/activity/bundleregistry.py
+++ /dev/null
@@ -1,131 +0,0 @@
-# Copyright (C) 2007, Red Hat, Inc.
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
-
-import os
-
-import gobject
-
-from sugar.activity.bundle import Bundle
-from sugar import env
-from sugar import util
-
-# http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
-def _get_data_dirs():
- if os.environ.has_key('XDG_DATA_DIRS'):
- return os.environ['XDG_DATA_DIRS'].split(':')
- else:
- return [ '/usr/local/share/', '/usr/share/' ]
-
-class _ServiceManager(object):
- """Internal class responsible for creating dbus service files
-
- DBUS services are defined in files which bind a service name
- to the name of an executable which provides the service name.
-
- In Sugar, the service files are automatically generated from
- the activity registry (by this class). When an activity's
- dbus launch service is requested, dbus will launch the
- specified executable in order to allow it to provide the
- requested activity-launching service.
-
- In the case of activities which provide a "class", instead of
- an "exec" attribute in their activity.info, the
- sugar-activity-factory script is used with an appropriate
- argument to service that bundle.
- """
- SERVICE_DIRECTORY = '~/.local/share/dbus-1/services'
- def __init__(self):
- service_dir = os.path.expanduser(self.SERVICE_DIRECTORY)
- if not os.path.isdir(service_dir):
- os.makedirs(service_dir)
-
- self._path = service_dir
-
- def add(self, bundle):
- util.write_service(bundle.get_service_name(),
- bundle.get_exec(), self._path)
-
-class BundleRegistry(gobject.GObject):
- """Service that tracks the available activity bundles"""
-
- __gsignals__ = {
- 'bundle-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
- ([gobject.TYPE_PYOBJECT]))
- }
-
- def __init__(self):
- gobject.GObject.__init__(self)
-
- self._bundles = {}
- self._search_path = []
- self._service_manager = _ServiceManager()
-
- def find_bundle(self, key):
- """Find a bundle in the registry"""
- key = key.lower()
-
- for bundle in self._bundles.values():
- name = bundle.get_name().lower()
- service_name = bundle.get_service_name().lower()
- if name.find(key) != -1 or service_name.find(key) != -1:
- return bundle
-
- return None
-
- 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 add_search_path(self, path):
- """Add a directory to the bundles search path"""
- self._search_path.append(path)
- self._scan_directory(path)
-
- def __iter__(self):
- return self._bundles.values().__iter__()
-
- def _scan_directory(self, path):
- if os.path.isdir(path):
- for f in os.listdir(path):
- bundle_dir = os.path.join(path, f)
- if os.path.isdir(bundle_dir) and \
- bundle_dir.endswith('.activity'):
- self.add_bundle(bundle_dir)
-
- def add_bundle(self, bundle_path):
- bundle = Bundle(bundle_path)
- if bundle.is_valid():
- self._bundles[bundle.get_service_name()] = bundle
- self._service_manager.add(bundle)
- self.emit('bundle-added', bundle)
- return True
- else:
- return False
-
-def get_registry():
- return _bundle_registry
-
-_bundle_registry = BundleRegistry()
-
-for path in _get_data_dirs():
- bundles_path = os.path.join(path, 'activities')
- _bundle_registry.add_search_path(bundles_path)
-
-_bundle_registry.add_search_path(env.get_user_activities_path())
diff --git a/sugar/activity/registry.py b/sugar/activity/registry.py
new file mode 100644
index 0000000..1efda45
--- /dev/null
+++ b/sugar/activity/registry.py
@@ -0,0 +1,58 @@
+# Copyright (C) 2006, Red Hat, Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import dbus
+
+_SHELL_SERVICE = "org.laptop.Shell"
+_SHELL_PATH = "/org/laptop/Shell"
+_REGISTRY_IFACE = "org.laptop.Shell.ActivityRegistry"
+
+def _activity_info_from_dict(info_dict):
+ return ActivityInfo(info_dict['name'], info_dict['icon'],
+ info_dict['service_name'], info_dict['path'])
+
+class ActivityInfo(object):
+ def __init__(self, name, icon, service_name, path):
+ self.name = name
+ self.icon = icon
+ self.service_name = service_name
+ self.path = path
+
+ def to_dict(self):
+ return { 'name' : self.name,
+ 'icon' : self.icon,
+ 'service_name' : self.service_name,
+ 'path' : self.path
+ }
+
+class ActivityRegistry(object):
+ def __init__(self):
+ bus = dbus.SessionBus()
+ bus_object = bus.get_object(_SHELL_SERVICE, _SHELL_PATH)
+ self._registry = dbus.Interface(bus_object, _REGISTRY_IFACE)
+
+ def get_activities_for_name(self, name):
+ result = []
+
+ activities = self._registry.GetActivitiesForName(name)
+ for info_dict in activities:
+ result.append(_activity_info_from_dict(info_dict))
+
+ return result
+
+ def get_activities_for_type(self, mime_type):
+ pass