diff options
Diffstat (limited to 'sugar')
-rw-r--r-- | sugar/activity/registry.py | 12 | ||||
-rw-r--r-- | sugar/bundle/activitybundle.py | 18 | ||||
-rw-r--r-- | sugar/bundle/bundle.py | 28 | ||||
-rw-r--r-- | sugar/bundle/contentbundle.py | 11 | ||||
-rw-r--r-- | sugar/util.py | 14 |
5 files changed, 60 insertions, 23 deletions
diff --git a/sugar/activity/registry.py b/sugar/activity/registry.py index 39c2b3c..8b1d440 100644 --- a/sugar/activity/registry.py +++ b/sugar/activity/registry.py @@ -43,6 +43,8 @@ class ActivityInfo(object): class ActivityRegistry(gobject.GObject): __gsignals__ = { 'activity-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])), + 'activity-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])) } def __init__(self): @@ -60,6 +62,7 @@ class ActivityRegistry(gobject.GObject): follow_name_owner_changes = True) self._registry = dbus.Interface(bus_object, _ACTIVITY_REGISTRY_IFACE) self._registry.connect_to_signal('ActivityAdded', self._activity_added_cb) + self._registry.connect_to_signal('ActivityRemoved', self._activity_removed_cb) # Two caches fo saving some travel across dbus. self._service_name_to_activity_info = {} @@ -133,6 +136,15 @@ class ActivityRegistry(gobject.GObject): self._mime_type_to_activities.clear() self.emit('activity-added', _activity_info_from_dict(info_dict)) + def remove_bundle(self, bundle_path): + return self._registry.RemoveBundle(bundle_path) + + def _activity_removed_cb(self, info_dict): + logging.debug('ActivityRegistry._activity_removed_cb: flushing caches') + self._service_name_to_activity_info.clear() + self._mime_type_to_activities.clear() + self.emit('activity-removed', _activity_info_from_dict(info_dict)) + _registry = None def get_registry(): diff --git a/sugar/bundle/activitybundle.py b/sugar/bundle/activitybundle.py index f77bdb7..0d5a5b4 100644 --- a/sugar/bundle/activitybundle.py +++ b/sugar/bundle/activitybundle.py @@ -252,8 +252,13 @@ class ActivityBundle(Bundle): raise RegistrationException def uninstall(self): - if not self.is_installed(): - raise NotInstalledException + if self._unpacked: + install_path = self._path + else: + if not self.is_installed(): + raise NotInstalledException + install_path = os.path.join(env.get_user_activities_path(), + self._zip_root_dir) xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share')) @@ -271,10 +276,11 @@ class ActivityBundle(Bundle): 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.readlink(path).startswith(install_path): os.remove(path) - self._uninstall() - - # FIXME: notify shell + self._uninstall(install_path) + + if not activity.get_registry().remove_bundle(install_path): + raise RegistrationException diff --git a/sugar/bundle/bundle.py b/sugar/bundle/bundle.py index 2657846..8ce3dda 100644 --- a/sugar/bundle/bundle.py +++ b/sugar/bundle/bundle.py @@ -130,19 +130,17 @@ class Bundle: zip.write(filename, os.path.join(base_dir, filename)) zip.close() - 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: - raise InvalidPathException - for root, dirs, files in os.walk(self._path, topdown=False): - for name in files: - os.remove(os.path.join(root, name)) - for name in dirs: - os.rmdir(os.path.join(root, name)) - os.rmdir(self._path) - else: - if not os.path.isfile(self._path) or ext != self._zipped_extension: + def _uninstall(self, install_path): + if not os.path.isdir(install_path): + raise InvalidPathException + if self._unzipped_extension is not None: + ext = os.path.splitext(install_path)[1] + if ext != self._unzipped_extension: raise InvalidPathException - os.remove(self._path) - + + for root, dirs, files in os.walk(install_path, topdown=False): + for name in files: + os.remove(os.path.join(root, name)) + for name in dirs: + os.rmdir(os.path.join(root, name)) + os.rmdir(install_path) diff --git a/sugar/bundle/contentbundle.py b/sugar/bundle/contentbundle.py index 7f9fddb..517ee9a 100644 --- a/sugar/bundle/contentbundle.py +++ b/sugar/bundle/contentbundle.py @@ -21,7 +21,7 @@ from ConfigParser import ConfigParser import os from sugar import env -from sugar.bundle.bundle import Bundle +from sugar.bundle.bundle import Bundle, NotInstalledException class ContentBundle(Bundle): """A Sugar content bundle @@ -178,5 +178,12 @@ class ContentBundle(Bundle): self._run_indexer() def uninstall(self): - self._uninstall() + if self._unpacked: + if not self.is_installed(): + raise NotInstalledException + install_dir = self._path + else: + install_dir = os.path.join(env.get_user_library_path(), + self._zip_root_dir) + self._uninstall(install_dir) self._run_indexer() diff --git a/sugar/util.py b/sugar/util.py index 5f01848..2780427 100644 --- a/sugar/util.py +++ b/sugar/util.py @@ -106,6 +106,20 @@ def write_service(name, bin, path): service_cp.write(fileobject) fileobject.close() +def delete_service(name, path): + """Delete a D-BUS service definition file + + Deletes a D-BUS service file previously + created by write_service(). + + name -- D-BUS service name, must be a valid + filename/D-BUS name + path -- directory containing the name.service + file + """ + + os.remove(os.path.join(path, name + '.service')) + def set_proc_title(title): """Sets the process title so ps and top show more descriptive names. This does not modify argv[0] |