Fix/Implement update in toolbox

This commit is contained in:
Jack Ha 2018-05-14 16:01:59 +02:00
parent 8718ee34c9
commit 0f0b6a9712
5 changed files with 57 additions and 21 deletions

View file

@ -136,14 +136,14 @@ class CuraPackageManager(QObject):
all_installed_ids = all_installed_ids.union(set(self._bundled_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.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():
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>
installed_packages_dict = {}
for package_id in all_installed_ids:
# Skip required plugins as they should not be tampered with
if package_id in Application.getInstance().getRequiredPlugins():
continue
@ -194,10 +194,10 @@ class CuraPackageManager(QObject):
return
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 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
installed_package_info = self.getInstalledPackageInfo(package_info["package_id"])
@ -235,19 +235,21 @@ class CuraPackageManager(QObject):
self.installedPackagesChanged.emit()
# 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)
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
if not self.isPackageInstalled(package_id):
Logger.log("i", "Attempt to remove package [%s] that is not installed, do nothing.", package_id)
return
# Remove from the delayed installation list if present
if package_id in self._to_install_package_dict:
del self._to_install_package_dict[package_id]
if package_id not in self._to_install_package_dict or force_add:
# Schedule for a delayed removal:
self._to_remove_package_set.add(package_id)
else:
# Remove from the delayed installation list if present
del self._to_install_package_dict[package_id]
self._saveManagementData()
self.installedPackagesChanged.emit()

View file

@ -37,7 +37,10 @@ Column
font: UM.Theme.getFont("default_bold")
}
}
onClicked: toolbox.update(model.id)
onClicked: {
// Must do all stuff in 1 function as the current ToolboxInstalledTile object is going to disappear...
toolbox.update(model.id)
}
}
ProgressBar
{

View file

@ -61,6 +61,7 @@ class Toolbox(QObject, Extension):
"plugins_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:
self._metadata = {
@ -216,13 +217,29 @@ class Toolbox(QObject, Extension):
@pyqtSlot(str)
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._updateInstalledModels()
self.metadataChanged.emit()
self._restart_required = True
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)
Logger.log("d", "Updating package [%s]..." % plugin_id)
self.uninstall(plugin_id)
self.startDownload(self.getRemotePackageURL(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)
def enable(self, plugin_id: str) -> None:
self._plugin_registry.enablePlugin(plugin_id)
@ -251,6 +268,23 @@ class Toolbox(QObject, Extension):
def restart(self):
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
@pyqtSlot(str, result = str)
def getRemotePackageURL(self, package_id: str) -> str:
remote_package = self.getRemotePackage(package_id)
if remote_package:
return remote_package["download_url"]
else:
return ""
# Checks
# --------------------------------------------------------------------------
@pyqtSlot(str, result = bool)
@ -259,10 +293,7 @@ class Toolbox(QObject, Extension):
if local_package is None:
return False
remote_package = None
for package in self._metadata["packages"]:
if package["package_id"] == package_id:
remote_package = package
remote_package = self.getRemotePackage(package_id)
if remote_package is None:
return False

View file

@ -736,7 +736,7 @@
"package_type": "material",
"display_name": "Dagoma Chromatik PLA",
"description": "Filament testé et approuvé pour les imprimantes 3D Dagoma. Chromatik est l'idéal pour débuter et suivre les tutoriels premiers pas. Il vous offre qualité et résistance pour chacune de vos impressions.",
"package_version": "1.0.0",
"package_version": "0.9.5",
"cura_version": 4,
"website": "https://dagoma.fr/boutique/filaments.html",
"author": {