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.)
This commit is contained in:
parent
380f3a2275
commit
b82c9c2c2f
@ -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
|
||||
|
||||
|
@ -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:
|
||||
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
|
||||
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:
|
||||
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)
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user