From 406b64b3318f07639410838dc380560ae7145c8e Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 12 Apr 2018 13:14:30 +0200 Subject: [PATCH 1/3] Remove unneeded code CURA-4644 --- cura/CuraPackageManager.py | 11 ----------- resources/qml/Cura.qml | 4 ---- 2 files changed, 15 deletions(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index 9c63de751d..ad9e6d19c3 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -4,7 +4,6 @@ from typing import Optional import json import os -import re import shutil import zipfile import tempfile @@ -37,8 +36,6 @@ class CuraPackageManager(QObject): self._to_remove_package_set = set() # a set of packages that need to be removed at the next start self._to_install_package_dict = {} # a dict of packages that need to be installed at the next start - self._semantic_version_regex = re.compile(r"^[0-9]+(.[0-9]+)+$") - installedPackagesChanged = pyqtSignal() # Emitted whenever the installed packages collection have been changed. def initialize(self): @@ -84,14 +81,6 @@ class CuraPackageManager(QObject): self._to_install_package_dict.clear() self._saveManagementData() - @pyqtSlot(str, result = bool) - def isPackageFile(self, file_name: str): - # TODO: remove this - extension = os.path.splitext(file_name)[1].strip(".") - if extension.lower() in ("curapackage",): - return True - return False - # 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]: if package_id in self._to_remove_package_set: diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index c632e7dbfd..e20a29fe16 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -345,10 +345,6 @@ UM.MainWindow pluginInstallDialog.open(); return; } - else if (CuraApplication.getCuraPackageManager().isPackageFile(drop.urls[0])) - { - CuraApplication.getCuraPackageManager().install(drop.urls[0]); - } } openDialog.handleOpenFileUrls(drop.urls); From 8a181ea395972b621ff28278a6cc7d396340bd4e Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 12 Apr 2018 13:25:22 +0200 Subject: [PATCH 2/3] Save curapackage into cache for delayed installation CURA-4644 Do not rely on the originally provided curapackage file because they can be gone after Cura restarts. Copy the curapackages into cache for delayed installation. --- cura/CuraPackageManager.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py index ad9e6d19c3..d07a3aced0 100644 --- a/cura/CuraPackageManager.py +++ b/cura/CuraPackageManager.py @@ -122,8 +122,16 @@ class CuraPackageManager(QObject): 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) + + target_file_path = os.path.join(package_cache_dir, package_id + ".curapackage") + shutil.copy2(filename, target_file_path) + self._to_install_package_dict[package_id] = {"package_info": package_info, - "filename": filename} + "filename": target_file_path} has_changes = True self._saveManagementData() @@ -175,6 +183,10 @@ class CuraPackageManager(QObject): package_id = package_info["package_id"] + if not os.path.exists(filename): + Logger.log("w", "Package [%s] file '%s' is missing, cannot install this package", package_id, filename) + return + Logger.log("i", "Installing package [%s] from file [%s]", package_id, filename) # If it's installed, remove it first and then install @@ -207,6 +219,9 @@ class CuraPackageManager(QObject): archive.close() + # Remove the file + os.remove(filename) + def __installPackageFiles(self, package_id: str, src_dir: str, dst_dir: str, need_to_rename_files: bool = True) -> None: shutil.move(src_dir, dst_dir) From 74a9ac6ba74eba8323b49cbe94a95366a55b822e Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 12 Apr 2018 13:30:24 +0200 Subject: [PATCH 3/3] Fix installPlugin in toolbox CURA-4644 --- plugins/Toolbox/src/Toolbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Toolbox/src/Toolbox.py b/plugins/Toolbox/src/Toolbox.py index d88a1c0f37..7d1fffdca5 100644 --- a/plugins/Toolbox/src/Toolbox.py +++ b/plugins/Toolbox/src/Toolbox.py @@ -466,7 +466,7 @@ class Toolbox(QObject, Extension): self.openLicenseDialog(package_info["package_id"], license_content, file_path) return - self._package_manager.installPlugin(file_path) + self.installPlugin(file_path) return