mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Merge branch 'bugfix-toolbox-update'
This commit is contained in:
commit
50dabdbac8
4 changed files with 52 additions and 20 deletions
|
@ -139,14 +139,14 @@ class CuraPackageManager(QObject):
|
||||||
all_installed_ids = all_installed_ids.union(set(self._bundled_package_dict.keys()))
|
all_installed_ids = all_installed_ids.union(set(self._bundled_package_dict.keys()))
|
||||||
if self._installed_package_dict.keys():
|
if self._installed_package_dict.keys():
|
||||||
all_installed_ids = all_installed_ids.union(set(self._installed_package_dict.keys()))
|
all_installed_ids = all_installed_ids.union(set(self._installed_package_dict.keys()))
|
||||||
|
all_installed_ids = all_installed_ids.difference(self._to_remove_package_set)
|
||||||
|
# If it's going to be installed and to be removed, then the package is being updated and it should be listed.
|
||||||
if self._to_install_package_dict.keys():
|
if self._to_install_package_dict.keys():
|
||||||
all_installed_ids = all_installed_ids.union(set(self._to_install_package_dict.keys()))
|
all_installed_ids = all_installed_ids.union(set(self._to_install_package_dict.keys()))
|
||||||
all_installed_ids = all_installed_ids.difference(self._to_remove_package_set)
|
|
||||||
|
|
||||||
# map of <package_type> -> <package_id> -> <package_info>
|
# map of <package_type> -> <package_id> -> <package_info>
|
||||||
installed_packages_dict = {}
|
installed_packages_dict = {}
|
||||||
for package_id in all_installed_ids:
|
for package_id in all_installed_ids:
|
||||||
|
|
||||||
# Skip required plugins as they should not be tampered with
|
# Skip required plugins as they should not be tampered with
|
||||||
if package_id in Application.getInstance().getRequiredPlugins():
|
if package_id in Application.getInstance().getRequiredPlugins():
|
||||||
continue
|
continue
|
||||||
|
@ -197,11 +197,6 @@ class CuraPackageManager(QObject):
|
||||||
return
|
return
|
||||||
package_id = package_info["package_id"]
|
package_id = package_info["package_id"]
|
||||||
|
|
||||||
# Check the delayed installation and removal lists first
|
|
||||||
if package_id in self._to_remove_package_set:
|
|
||||||
self._to_remove_package_set.remove(package_id)
|
|
||||||
has_changes = True
|
|
||||||
|
|
||||||
# Check if it is installed
|
# Check if it is installed
|
||||||
installed_package_info = self.getInstalledPackageInfo(package_info["package_id"])
|
installed_package_info = self.getInstalledPackageInfo(package_info["package_id"])
|
||||||
to_install_package = installed_package_info is None # Install if the package has not been installed
|
to_install_package = installed_package_info is None # Install if the package has not been installed
|
||||||
|
@ -238,19 +233,27 @@ class CuraPackageManager(QObject):
|
||||||
self.installedPackagesChanged.emit()
|
self.installedPackagesChanged.emit()
|
||||||
|
|
||||||
# Schedules the given package to be removed upon the next start.
|
# Schedules the given package to be removed upon the next start.
|
||||||
|
# \param package_id id of the package
|
||||||
|
# \param force_add is used when updating. In that case you actually want to uninstall & install
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def removePackage(self, package_id: str) -> None:
|
def removePackage(self, package_id: str, force_add: bool = False) -> None:
|
||||||
# Check the delayed installation and removal lists first
|
# Check the delayed installation and removal lists first
|
||||||
if not self.isPackageInstalled(package_id):
|
if not self.isPackageInstalled(package_id):
|
||||||
Logger.log("i", "Attempt to remove package [%s] that is not installed, do nothing.", package_id)
|
Logger.log("i", "Attempt to remove package [%s] that is not installed, do nothing.", package_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Remove from the delayed installation list if present
|
# Temp hack
|
||||||
if package_id in self._to_install_package_dict:
|
if package_id not in self._installed_package_dict and package_id in self._bundled_package_dict:
|
||||||
del self._to_install_package_dict[package_id]
|
Logger.log("i", "Not uninstalling [%s] because it is a bundled package.")
|
||||||
|
return
|
||||||
|
|
||||||
# Schedule for a delayed removal:
|
if package_id not in self._to_install_package_dict or force_add:
|
||||||
self._to_remove_package_set.add(package_id)
|
# Schedule for a delayed removal:
|
||||||
|
self._to_remove_package_set.add(package_id)
|
||||||
|
else:
|
||||||
|
if package_id in self._to_install_package_dict:
|
||||||
|
# Remove from the delayed installation list if present
|
||||||
|
del self._to_install_package_dict[package_id]
|
||||||
|
|
||||||
self._saveManagementData()
|
self._saveManagementData()
|
||||||
self.installedPackagesChanged.emit()
|
self.installedPackagesChanged.emit()
|
||||||
|
|
|
@ -112,4 +112,4 @@ Item
|
||||||
onMetadataChanged: canUpdate = toolbox.canUpdate(model.id)
|
onMetadataChanged: canUpdate = toolbox.canUpdate(model.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,4 +90,4 @@ Column
|
||||||
}
|
}
|
||||||
onClicked: toolbox.uninstall(model.id)
|
onClicked: toolbox.uninstall(model.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ class Toolbox(QObject, Extension):
|
||||||
"plugins_showcase": QUrl("{base_url}/showcase".format(base_url = self._api_url)),
|
"plugins_showcase": QUrl("{base_url}/showcase".format(base_url = self._api_url)),
|
||||||
"materials_showcase": QUrl("{base_url}/showcase".format(base_url = self._api_url))
|
"materials_showcase": QUrl("{base_url}/showcase".format(base_url = self._api_url))
|
||||||
}
|
}
|
||||||
|
self._to_update = [] # Package_ids that are waiting to be updated
|
||||||
|
|
||||||
# Data:
|
# Data:
|
||||||
self._metadata = {
|
self._metadata = {
|
||||||
|
@ -216,13 +217,35 @@ class Toolbox(QObject, Extension):
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def uninstall(self, plugin_id: str) -> None:
|
def uninstall(self, plugin_id: str) -> None:
|
||||||
self._package_manager.removePackage(plugin_id)
|
self._package_manager.removePackage(plugin_id, force_add = True)
|
||||||
self.installChanged.emit()
|
self.installChanged.emit()
|
||||||
self._updateInstalledModels()
|
self._updateInstalledModels()
|
||||||
self.metadataChanged.emit()
|
self.metadataChanged.emit()
|
||||||
self._restart_required = True
|
self._restart_required = True
|
||||||
self.restartRequiredChanged.emit()
|
self.restartRequiredChanged.emit()
|
||||||
|
|
||||||
|
## Actual update packages that are in self._to_update
|
||||||
|
def _update(self) -> None:
|
||||||
|
if self._to_update:
|
||||||
|
plugin_id = self._to_update.pop(0)
|
||||||
|
remote_package = self.getRemotePackage(plugin_id)
|
||||||
|
if remote_package:
|
||||||
|
download_url = remote_package["download_url"]
|
||||||
|
Logger.log("d", "Updating package [%s]..." % 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)
|
||||||
|
|
||||||
|
if self._to_update:
|
||||||
|
self._application.callLater(self._update)
|
||||||
|
|
||||||
|
## Update a plugin by plugin_id
|
||||||
|
@pyqtSlot(str)
|
||||||
|
def update(self, plugin_id: str) -> None:
|
||||||
|
self._to_update.append(plugin_id)
|
||||||
|
self._application.callLater(self._update)
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def enable(self, plugin_id: str) -> None:
|
def enable(self, plugin_id: str) -> None:
|
||||||
self._plugin_registry.enablePlugin(plugin_id)
|
self._plugin_registry.enablePlugin(plugin_id)
|
||||||
|
@ -251,6 +274,15 @@ class Toolbox(QObject, Extension):
|
||||||
def restart(self):
|
def restart(self):
|
||||||
CuraApplication.getInstance().windowClosed()
|
CuraApplication.getInstance().windowClosed()
|
||||||
|
|
||||||
|
def getRemotePackage(self, package_id: str) -> Optional[Dict]:
|
||||||
|
# TODO: make the lookup in a dict, not a loop. canUpdate is called for every item.
|
||||||
|
remote_package = None
|
||||||
|
for package in self._metadata["packages"]:
|
||||||
|
if package["package_id"] == package_id:
|
||||||
|
remote_package = package
|
||||||
|
break
|
||||||
|
return remote_package
|
||||||
|
|
||||||
# Checks
|
# Checks
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
@pyqtSlot(str, result = bool)
|
@pyqtSlot(str, result = bool)
|
||||||
|
@ -259,10 +291,7 @@ class Toolbox(QObject, Extension):
|
||||||
if local_package is None:
|
if local_package is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
remote_package = None
|
remote_package = self.getRemotePackage(package_id)
|
||||||
for package in self._metadata["packages"]:
|
|
||||||
if package["package_id"] == package_id:
|
|
||||||
remote_package = package
|
|
||||||
if remote_package is None:
|
if remote_package is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue