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.
This commit is contained in:
Lipu Fei 2018-04-12 13:25:22 +02:00
parent 406b64b331
commit 8a181ea395

View File

@ -122,8 +122,16 @@ class CuraPackageManager(QObject):
if to_install_package: if to_install_package:
Logger.log("i", "Package [%s] version [%s] is scheduled to be installed.", Logger.log("i", "Package [%s] version [%s] is scheduled to be installed.",
package_id, package_info["package_version"]) 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, self._to_install_package_dict[package_id] = {"package_info": package_info,
"filename": filename} "filename": target_file_path}
has_changes = True has_changes = True
self._saveManagementData() self._saveManagementData()
@ -175,6 +183,10 @@ class CuraPackageManager(QObject):
package_id = package_info["package_id"] 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) Logger.log("i", "Installing package [%s] from file [%s]", package_id, filename)
# If it's installed, remove it first and then install # If it's installed, remove it first and then install
@ -207,6 +219,9 @@ class CuraPackageManager(QObject):
archive.close() 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: 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) shutil.move(src_dir, dst_dir)