From 70940b85738bfdd297e18ee259a949fcda71e3e9 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 25 Sep 2007 14:50:11 -0400 Subject: [PATCH 1/2] fix _uninstall() --- sugar/bundle/bundle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sugar/bundle/bundle.py b/sugar/bundle/bundle.py index a2e9076e..75b4b38b 100644 --- a/sugar/bundle/bundle.py +++ b/sugar/bundle/bundle.py @@ -127,7 +127,7 @@ class Bundle: zip.write(filename, os.path.join(base_dir, filename)) zip.close() - def remove(self): + def _uninstall(self): ext = os.path.splitext(self._path)[1] if self._unpacked: if not os.path.isdir(self._path) or ext != self._unzipped_extension: @@ -137,7 +137,7 @@ class Bundle: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) - os.rmdir(root) + os.rmdir(self._path) else: if not os.path.isfile(self._path) or ext != self._zipped_extension: raise InvalidPathException From 8ff6cbab1ea5f2b45064c278fbf77e4a1931f5c2 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 25 Sep 2007 14:50:38 -0400 Subject: [PATCH 2/2] Fix MIME icon installation (#2458) and icon/mimetype info uninstallation --- services/shell/objecttypeservice.py | 33 +++++++++++++++++++ sugar/bundle/activitybundle.py | 50 +++++++++++++++++++++++------ 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/services/shell/objecttypeservice.py b/services/shell/objecttypeservice.py index 4e806d4a..c4910f78 100644 --- a/services/shell/objecttypeservice.py +++ b/services/shell/objecttypeservice.py @@ -16,9 +16,13 @@ import dbus import dbus.service +import gnomevfs +import gtk from gettext import gettext as _ +import bundleregistry + _REGISTRY_IFACE = "org.laptop.ObjectTypeRegistry" _REGISTRY_PATH = "/org/laptop/ObjectTypeRegistry" @@ -53,6 +57,11 @@ class ObjectTypeRegistry(dbus.service.Object): 'text-uri-list', ['text/x-moz-url', 'text/uri-list']) + self._activity_registry = bundleregistry.get_registry() + for bundle in self._activity_registry: + self._add_activity(self._activity_registry, bundle) + self._activity_registry.connect('bundle-added', self._add_activity) + def _add_primitive(self, type_id, name, icon, mime_types): object_type = {'type_id': type_id, 'name': name, @@ -60,6 +69,30 @@ class ObjectTypeRegistry(dbus.service.Object): 'mime_types': mime_types} self._types[type_id] = object_type + def _add_activity(self, activity_registry, bundle): + mime_types = bundle.get_mime_types() + if mime_types is None: + return + + icon_theme = gtk.icon_theme_get_default() + for mime_type in mime_types: + if self._get_type_for_mime(mime_type) is not None: + continue + + name = gnomevfs.mime_get_description(mime_type) + if name is None: + continue + + icon = mime_type.replace('/', '-') + if icon_theme.lookup_icon(icon, gtk.ICON_SIZE_BUTTON, 0) is None: + continue + + object_type = {'type_id': mime_type, + 'name': name, + 'icon': icon, + 'mime_types': [mime_type]} + self._types[mime_type] = object_type + def _get_type_for_mime(self, mime_type): for object_type in self._types.values(): if mime_type in object_type['mime_types']: diff --git a/sugar/bundle/activitybundle.py b/sugar/bundle/activitybundle.py index 07a52551..f77bdb7a 100644 --- a/sugar/bundle/activitybundle.py +++ b/sugar/bundle/activitybundle.py @@ -213,8 +213,6 @@ class ActivityBundle(Bundle): self._unzip(install_dir) install_path = os.path.join(install_dir, self._zip_root_dir) - if not activity.get_registry().add_bundle(install_path): - raise RegistrationException xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share')) @@ -229,20 +227,54 @@ class ActivityBundle(Bundle): os.spawnlp(os.P_WAIT, 'update-mime-database', 'update-mime-database', mime_dir) - icons_dir = os.path.join(install_path, 'activity', 'mime-icons') - if os.path.isdir(icons_dir): - installed_icons_dir = os.path.join(xdg_data_home, 'icons/sugar/scalable/mimetypes') + mime_types = self.get_mime_types() + if mime_types is not None: + installed_icons_dir = os.path.join(xdg_data_home, + 'icons/sugar/scalable/mimetypes') if not os.path.isdir(installed_icons_dir): os.makedirs(installed_icons_dir) - for file in os.listdir(icons_dir): - if file.endswith('.svg') or file.endswith('.icon'): - os.symlink(os.path.join(icons_dir, file), - os.path.join(installed_icons_dir, file)) + + for mime_type in mime_types: + mime_icon_base = os.path.join(install_path, 'activity', + mime_type.replace('/', '-')) + svg_file = mime_icon_base + '.svg' + info_file = mime_icon_base + '.icon' + if os.path.isfile(svg_file): + os.symlink(svg_file, + os.path.join(installed_icons_dir, + os.path.basename(svg_file))) + if os.path.isfile(info_file): + os.symlink(info_file, + os.path.join(installed_icons_dir, + os.path.basename(info_file))) + + if not activity.get_registry().add_bundle(install_path): + raise RegistrationException def uninstall(self): if not self.is_installed(): raise NotInstalledException + xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share')) + + mime_dir = os.path.join(xdg_data_home, 'mime') + installed_mime_path = os.path.join(mime_dir, 'packages', '%s.xml' % self._service_name) + if os.path.exists(installed_mime_path): + os.remove(installed_mime_path) + os.spawnlp(os.P_WAIT, 'update-mime-database', + 'update-mime-database', mime_dir) + + mime_types = self.get_mime_types() + if mime_types is not None: + installed_icons_dir = os.path.join(xdg_data_home, + 'icons/sugar/scalable/mimetypes') + for file in os.listdir(installed_icons_dir): + path = os.path.join(installed_icons_dir, file) + if os.path.islink(path) and \ + os.readlink(path).startswith(self._path): + os.remove(path) + self._uninstall() + # FIXME: notify shell