From 7ee085fe50b84f4aa1993fcf805e06d3de7e3253 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Tue, 1 May 2018 10:47:28 +0200 Subject: [PATCH] Check all subdirs in data storage dir for package removal --- cura/CuraPackageManager.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index 04ca16219b..baf0c153c9 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -245,22 +245,17 @@ class CuraPackageManager(QObject): # Removes everything associated with the given package ID. def _purgePackage(self, package_id: str) -> None: - # Get all folders that need to be checked for installed packages, including: - # - materials - # - qualities - # - plugins - from cura.CuraApplication import CuraApplication - dirs_to_check = [ - Resources.getStoragePath(CuraApplication.ResourceTypes.MaterialInstanceContainer), - Resources.getStoragePath(CuraApplication.ResourceTypes.QualityInstanceContainer), - os.path.join(os.path.abspath(Resources.getDataStoragePath()), "plugins"), - ] + # Iterate through all directories in the data storage directory and look for sub-directories that belong to + # the package we need to remove, that is the sub-dirs with the package_id as names, and remove all those dirs. + data_storage_dir = os.path.abspath(Resources.getDataStoragePath()) - for root_dir in dirs_to_check: - package_dir = os.path.join(root_dir, package_id) - if os.path.exists(package_dir): - Logger.log("i", "Removing '%s' for package [%s]", package_dir, package_id) + for root, dir_names, _ in os.walk(data_storage_dir): + for dir_name in dir_names: + package_dir = os.path.join(root, dir_name, package_id) + if os.path.exists(package_dir): + Logger.log("i", "Removing '%s' for package [%s]", package_dir, package_id) shutil.rmtree(package_dir) + break # Installs all files associated with the given package. def _installPackage(self, installation_package_data: dict):