From 9281c235557e22102fc5d6f418178c5c36cb27a9 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 15 May 2018 16:23:54 +0200 Subject: [PATCH] Fix uninstallable user package which was also bundled; make update package somewhat better by not trying to uninstall builtin package --- cura/CuraPackageManager.py | 10 +++++++--- plugins/Toolbox/src/Toolbox.py | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index ec75174db4..2006c8804b 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -171,7 +171,7 @@ class CuraPackageManager(QObject): package_info["is_active"] = self._plugin_registry.isActivePlugin(package_id) # If the package ID is in bundled, label it as such - package_info["is_bundled"] = package_info["package_id"] in self._bundled_package_dict.keys() + package_info["is_bundled"] = package_info["package_id"] in self._bundled_package_dict.keys() and not self.isUserInstalledPackage(package_info["package_id"]) # If there is not a section in the dict for this type, add it if package_info["package_type"] not in installed_packages_dict: @@ -182,7 +182,7 @@ class CuraPackageManager(QObject): return installed_packages_dict - # Checks if the given package is installed. + # Checks if the given package is installed (at all). def isPackageInstalled(self, package_id: str) -> bool: return self.getInstalledPackageInfo(package_id) is not None @@ -242,7 +242,7 @@ class CuraPackageManager(QObject): Logger.log("i", "Attempt to remove package [%s] that is not installed, do nothing.", package_id) return - # Temp hack + # Extra safety check if package_id not in self._installed_package_dict and package_id in self._bundled_package_dict: Logger.log("i", "Not uninstalling [%s] because it is a bundled package.") return @@ -258,6 +258,10 @@ class CuraPackageManager(QObject): self._saveManagementData() self.installedPackagesChanged.emit() + ## Is the package an user installed package? + def isUserInstalledPackage(self, package_id: str): + return package_id in self._installed_package_dict + # Removes everything associated with the given package ID. def _purgePackage(self, package_id: str) -> None: # Iterate through all directories in the data storage directory and look for sub-directories that belong to diff --git a/plugins/Toolbox/src/Toolbox.py b/plugins/Toolbox/src/Toolbox.py index 07a7bcbe73..622198666d 100644 --- a/plugins/Toolbox/src/Toolbox.py +++ b/plugins/Toolbox/src/Toolbox.py @@ -232,7 +232,8 @@ class Toolbox(QObject, Extension): if remote_package: download_url = remote_package["download_url"] Logger.log("d", "Updating package [%s]..." % plugin_id) - self.uninstall(plugin_id) + if self._package_manager.isUserInstalledPackage(plugin_id): + self.uninstall(plugin_id) self.startDownload(download_url) else: Logger.log("e", "Could not update package [%s] because there is no remote package info available.", plugin_id)