Fix downgrade packages to bundled version

CURA-5296
This commit is contained in:
Lipu Fei 2018-05-28 11:18:22 +02:00
parent 689b88a024
commit ad131ab30c
2 changed files with 13 additions and 5 deletions

View file

@ -111,6 +111,12 @@ class CuraPackageManager(QObject):
del self._to_install_package_dict[package_id] del self._to_install_package_dict[package_id]
self._saveManagementData() self._saveManagementData()
def getBundledPackageInfo(self, package_id: str) -> Optional[dict]:
package_info = None
if package_id in self._bundled_package_dict:
package_info = self._bundled_package_dict[package_id]["package_info"]
return package_info
# Checks the given package is installed. If so, return a dictionary that contains the package's information. # Checks the given package is installed. If so, return a dictionary that contains the package's information.
def getInstalledPackageInfo(self, package_id: str) -> Optional[dict]: def getInstalledPackageInfo(self, package_id: str) -> Optional[dict]:
if package_id in self._to_remove_package_set: if package_id in self._to_remove_package_set:

View file

@ -320,17 +320,19 @@ class Toolbox(QObject, Extension):
@pyqtSlot(str, result = bool) @pyqtSlot(str, result = bool)
def canDowngrade(self, package_id: str) -> bool: def canDowngrade(self, package_id: str) -> bool:
# If the currently installed version is higher than the bundled version (if present), the we can downgrade
# this package.
local_package = self._package_manager.getInstalledPackageInfo(package_id) local_package = self._package_manager.getInstalledPackageInfo(package_id)
if local_package is None: if local_package is None:
return False return False
remote_package = self.getRemotePackage(package_id) bundled_package = self._package_manager.getBundledPackageInfo(package_id)
if remote_package is None: if bundled_package is None:
return False return False
local_version = Version(local_package["package_version"]) local_version = Version(local_package["package_version"])
remote_version = Version(remote_package["package_version"]) bundled_version = Version(bundled_package["package_version"])
return remote_version < local_version return bundled_version < local_version
@pyqtSlot(str, result = bool) @pyqtSlot(str, result = bool)
def isInstalled(self, package_id: str) -> bool: def isInstalled(self, package_id: str) -> bool: