From 0d66850bd4cff54b4942721f227d13ebdad4c85b Mon Sep 17 00:00:00 2001 From: Ruben D Date: Wed, 2 May 2018 12:40:59 +0200 Subject: [PATCH 1/8] Code style improvements According to our guidelines: Brackets on new line, spaces around binary operators but not within brackets. Contributes to issue CURA-5035. --- .../Toolbox/resources/qml/ToolboxDownloadsShowcaseTile.qml | 3 ++- plugins/Toolbox/resources/qml/ToolboxInstalledTile.qml | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/Toolbox/resources/qml/ToolboxDownloadsShowcaseTile.qml b/plugins/Toolbox/resources/qml/ToolboxDownloadsShowcaseTile.qml index 0a2924c600..a699e9dae6 100644 --- a/plugins/Toolbox/resources/qml/ToolboxDownloadsShowcaseTile.qml +++ b/plugins/Toolbox/resources/qml/ToolboxDownloadsShowcaseTile.qml @@ -33,7 +33,8 @@ Item top: parent.top horizontalCenter: parent.horizontalCenter } - Image { + Image + { anchors.centerIn: parent width: UM.Theme.getSize("toolbox_thumbnail_large").width - 2 * UM.Theme.getSize("default_margin").width height: UM.Theme.getSize("toolbox_thumbnail_large").height - 2 * UM.Theme.getSize("default_margin").height diff --git a/plugins/Toolbox/resources/qml/ToolboxInstalledTile.qml b/plugins/Toolbox/resources/qml/ToolboxInstalledTile.qml index e8c9a17eba..ff27e004b2 100644 --- a/plugins/Toolbox/resources/qml/ToolboxInstalledTile.qml +++ b/plugins/Toolbox/resources/qml/ToolboxInstalledTile.qml @@ -75,7 +75,7 @@ Item { if (model.author_email) { - return ""+model.author_name+"" + return "" + model.author_name + "" } else { @@ -87,7 +87,7 @@ Item wrapMode: Text.WordWrap verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignLeft - onLinkActivated: Qt.openUrlExternally("mailto:"+model.author_email+"?Subject=Cura: "+model.name+" Plugin") + onLinkActivated: Qt.openUrlExternally("mailto:" + model.author_email + "?Subject=Cura: " + model.name + " Plugin") color: model.enabled ? UM.Theme.getColor("text") : UM.Theme.getColor("lining") } } @@ -153,7 +153,7 @@ Item } else { - toolbox.uninstall( model.id ) + toolbox.uninstall(model.id) } } } From 8250ea83667abc5ef4d244c9d1a5af96c40f436f Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 2 May 2018 12:46:58 +0200 Subject: [PATCH 2/8] Add version for cura package management JSON CIRA-5035 --- cura/CuraPackageManager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index e90b776e28..5dc9a7e680 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -16,6 +16,7 @@ from UM.Resources import Resources from UM.Version import Version class CuraPackageManager(QObject): + Version = 1 # The prefix that's added to all files for an installed package to avoid naming conflicts with user created # files. @@ -65,7 +66,8 @@ class CuraPackageManager(QObject): container_registry = self._application.getContainerRegistry() with container_registry.lockFile(): with open(self._package_management_file_path, "w", encoding = "utf-8") as f: - data_dict = {"installed": self._installed_package_dict, + data_dict = {"version": CuraPackageManager.Version, + "installed": self._installed_package_dict, "to_remove": list(self._to_remove_package_set), "to_install": self._to_install_package_dict} data_dict["to_remove"] = list(data_dict["to_remove"]) From d4cf944e1153a64285656505d2e3707add73fb8a Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 2 May 2018 12:49:50 +0200 Subject: [PATCH 3/8] Simplify code CURA-5035 --- cura/CuraPackageManager.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index 5dc9a7e680..331f2ace84 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -106,8 +106,7 @@ class CuraPackageManager(QObject): for section, packages in self.getAllInstalledPackagesInfo().items(): for package in packages: if package["package_id"] == package_id: - package_info = package - return package_info + return package return None From 5cc5f32a734cf23db14b0b714bd085c8fc770034 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 2 May 2018 12:52:27 +0200 Subject: [PATCH 4/8] Remove unnecessary is_bundled modifications CURA-5035 --- cura/CuraPackageManager.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index 331f2ace84..a0b02b8d79 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -95,12 +95,10 @@ class CuraPackageManager(QObject): if package_id in self._to_install_package_dict: package_info = self._to_install_package_dict[package_id]["package_info"] - package_info["is_bundled"] = False return package_info if package_id in self._installed_package_dict: package_info = self._installed_package_dict.get(package_id) - package_info["is_bundled"] = False return package_info for section, packages in self.getAllInstalledPackagesInfo().items(): From 09af97634d3a3170ea2f76b220725417a3ecfb91 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 2 May 2018 12:53:31 +0200 Subject: [PATCH 5/8] Simplify code CURA-5035 --- cura/CuraPackageManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index a0b02b8d79..bd1d784c9b 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -112,7 +112,7 @@ class CuraPackageManager(QObject): installed_package_id_set = set(self._installed_package_dict.keys()) | set(self._to_install_package_dict.keys()) installed_package_id_set = installed_package_id_set.difference(self._to_remove_package_set) - managed_package_id_set = set(installed_package_id_set) | self._to_remove_package_set + managed_package_id_set = installed_package_id_set | self._to_remove_package_set # TODO: For absolutely no reason, this function seems to run in a loop # even though no loop is ever called with it. From 49649e3d4a90413f2df37e795ddb5900ad29eeff Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 2 May 2018 12:57:24 +0200 Subject: [PATCH 6/8] Add final so the management JSON is always saved CURA-5035 --- cura/CuraPackageManager.py | 73 ++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index bd1d784c9b..4006cddd77 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -183,46 +183,51 @@ class CuraPackageManager(QObject): # Schedules the given package file to be installed upon the next start. @pyqtSlot(str) def installPackage(self, filename: str) -> None: - # Get package information - package_info = self.getPackageInfo(filename) - package_id = package_info["package_id"] - has_changes = False - # 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 + try: + # Get package information + package_info = self.getPackageInfo(filename) + package_id = package_info["package_id"] - # Check if it is installed - 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 - if installed_package_info is not None: - # Compare versions and only schedule the installation if the given package is newer - new_version = package_info["package_version"] - installed_version = installed_package_info["package_version"] - if Version(new_version) > Version(installed_version): - Logger.log("i", "Package [%s] version [%s] is newer than the installed version [%s], update it.", - package_id, new_version, installed_version) - to_install_package = 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 - if to_install_package: - Logger.log("i", "Package [%s] version [%s] is scheduled to be installed.", - package_id, package_info["package_version"]) - # Copy the file to cache dir so we don't need to rely on the original file to be present - package_cache_dir = os.path.join(os.path.abspath(Resources.getCacheStoragePath()), "cura_packages") - if not os.path.exists(package_cache_dir): - os.makedirs(package_cache_dir, exist_ok=True) + # Check if it is installed + 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 + if installed_package_info is not None: + # Compare versions and only schedule the installation if the given package is newer + new_version = package_info["package_version"] + installed_version = installed_package_info["package_version"] + if Version(new_version) > Version(installed_version): + Logger.log("i", "Package [%s] version [%s] is newer than the installed version [%s], update it.", + package_id, new_version, installed_version) + to_install_package = True - target_file_path = os.path.join(package_cache_dir, package_id + ".curapackage") - shutil.copy2(filename, target_file_path) + if to_install_package: + # Need to use the lock file to prevent concurrent I/O issues. + with self._container_registry.lockFile(): + Logger.log("i", "Package [%s] version [%s] is scheduled to be installed.", + package_id, package_info["package_version"]) + # Copy the file to cache dir so we don't need to rely on the original file to be present + package_cache_dir = os.path.join(os.path.abspath(Resources.getCacheStoragePath()), "cura_packages") + if not os.path.exists(package_cache_dir): + os.makedirs(package_cache_dir, exist_ok=True) - self._to_install_package_dict[package_id] = {"package_info": package_info, - "filename": target_file_path} - has_changes = True + target_file_path = os.path.join(package_cache_dir, package_id + ".curapackage") + shutil.copy2(filename, target_file_path) - self._saveManagementData() - if has_changes: - self.installedPackagesChanged.emit() + self._to_install_package_dict[package_id] = {"package_info": package_info, + "filename": target_file_path} + has_changes = True + except: + Logger.logException("c", "Failed to install package file '%s'", filename) + finally: + self._saveManagementData() + if has_changes: + self.installedPackagesChanged.emit() # Schedules the given package to be removed upon the next start. @pyqtSlot(str) From ad3317a9929e69a2758fa27c5401b5d0d9cc5990 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 2 May 2018 13:00:00 +0200 Subject: [PATCH 7/8] Fix docs for VersionUpgrade 3.3 to 3.4 CURA-5035 --- .../VersionUpgrade33to34/VersionUpgrade33to34.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade33to34/VersionUpgrade33to34.py b/plugins/VersionUpgrade/VersionUpgrade33to34/VersionUpgrade33to34.py index 4e7b09564a..17abace547 100644 --- a/plugins/VersionUpgrade/VersionUpgrade33to34/VersionUpgrade33to34.py +++ b/plugins/VersionUpgrade/VersionUpgrade33to34/VersionUpgrade33to34.py @@ -7,13 +7,13 @@ import io #To serialise the preference files afterwards. from UM.VersionUpgrade import VersionUpgrade #We're inheriting from this. -## Upgrades configurations from the state they were in at version 3.2 to the -# state they should be in at version 3.3. +## Upgrades configurations from the state they were in at version 3.3 to the +# state they should be in at version 3.4. class VersionUpgrade33to34(VersionUpgrade): - ## Gets the version number from a CFG file in Uranium's 3.2 format. + ## Gets the version number from a CFG file in Uranium's 3.3 format. # - # Since the format may change, this is implemented for the 3.2 format only + # Since the format may change, this is implemented for the 3.3 format only # and needs to be included in the version upgrade system rather than # globally in Uranium. # From 554ebb6617c1be1db84b8df3cdc8b1a2e2cf9255 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 2 May 2018 13:05:55 +0200 Subject: [PATCH 8/8] Clean up PackagesModel CURA-5035 --- plugins/Toolbox/src/PackagesModel.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/Toolbox/src/PackagesModel.py b/plugins/Toolbox/src/PackagesModel.py index 34ea5b8d42..e485b579b5 100644 --- a/plugins/Toolbox/src/PackagesModel.py +++ b/plugins/Toolbox/src/PackagesModel.py @@ -6,7 +6,6 @@ from typing import Dict from PyQt5.QtCore import Qt, pyqtProperty -from UM.Application import Application from UM.Qt.ListModel import ListModel @@ -43,7 +42,6 @@ class PackagesModel(ListModel): items = [] for package in self._metadata: - print(package["author"]) items.append({ "id": package["package_id"], "type": package["package_type"],