diff options
author | Jelle Spijker <spijker.jelle@gmail.com> | 2021-12-05 17:11:35 +0300 |
---|---|---|
committer | Jelle Spijker <spijker.jelle@gmail.com> | 2021-12-05 17:11:35 +0300 |
commit | 09709ede8b27f02ae0dc2f8131a15f9ca94183c6 (patch) | |
tree | d1a0d20c8ae8080a5ccb43d2eb5900af8beda21b /cura | |
parent | 42e7ef4a8989786576636d517c61d659651fdf0a (diff) |
Fix duplicate packages in get AlllocalPackages
The helper class is needed because dict's aren't hashable
which complicates the `in` check.
Contributes to: CURA-8587
Diffstat (limited to 'cura')
-rw-r--r-- | cura/CuraPackageManager.py | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index 98e0e592aa..21cd0c69dc 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -23,7 +23,7 @@ class CuraPackageManager(PackageManager): self.installedPackagesChanged.connect(self._updateLocallyInstalledPackages) def _updateLocallyInstalledPackages(self): - self._locally_installed_packages = list(self.iterateAllLocalPackages()) + self._locally_installed_packages = self.getAllLocalPackages() @property def locally_installed_packages(self): @@ -66,24 +66,29 @@ class CuraPackageManager(PackageManager): return machine_with_materials, machine_with_qualities - def iterateAllLocalPackages(self) -> Generator[Dict[str, Any], None, None]: - """ A generator which returns an unordered list of all the PackageModels""" - handled_packages = {} - - for packages in self.getAllInstalledPackagesInfo().values(): - for package_info in packages: - handled_packages.add(package_info["package_id"]) - yield package_info - - # Get all to be removed package_info's. These packages are still used in the current session so the user might - # still want to interact with these. - for package_data in self.getPackagesToRemove().values(): - if not package_data["package_info"]["package_id"] in handled_packages: - handled_packages.add(package_data["package_info"]["package_id"]) - yield package_data["package_info"] - - # Get all to be installed package_info's. Since the user might want to interact with these - for package_data in self.getPackagesToInstall().values(): - if not package_data["package_info"]["package_id"] in handled_packages: - handled_packages.add(package_data["package_info"]["package_id"]) - yield package_data["package_info"] + def getAllLocalPackages(self) -> List[Dict[str, Any]]: + """ returns an unordered list of all the package_info installed, to be installed or to be returned""" + + class PkgInfo: + # Needed helper class because a dict isn't hashable + def __init__(self, package_info): + self._info = package_info + + def __contains__(self, item): + return item == self._info["package_id"] + + def __repr__(self): + return repr(self._info) + + def __iter__(self): + for k, v in self._info.items(): + yield k, v + + def asdict(self): + return self._info + + packages = [PkgInfo(package_info) for package in self.getAllInstalledPackagesInfo().values() for package_info in package] + packages.extend([PkgInfo(package["package_info"]) for package in self.getPackagesToRemove().values() if package["package_info"]["package_id"] not in packages]) + packages.extend([PkgInfo(package["package_info"]) for package in self.getPackagesToInstall().values() if package["package_info"]["package_id"] not in packages]) + + return [dict(package) for package in packages] |