From b82c9c2c2f872eecd95f802b28b0bdadbb5472ed Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Thu, 04 Oct 2007 18:58:43 +0000 Subject: Reorganize the uninstall code for #3151 (Make it so you can build a Bundle object from the zip file but still use its uninstall() method to uninstall the unzipped version.) --- diff --git a/sugar/bundle/activitybundle.py b/sugar/bundle/activitybundle.py index f77bdb7..d13f93c 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,10 @@ 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() + self._uninstall(install_path) # FIXME: notify shell 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() -- cgit v0.9.1