mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Add final so the management JSON is always saved
CURA-5035
This commit is contained in:
parent
09af97634d
commit
49649e3d4a
1 changed files with 39 additions and 34 deletions
|
@ -183,46 +183,51 @@ class CuraPackageManager(QObject):
|
||||||
# Schedules the given package file to be installed upon the next start.
|
# Schedules the given package file to be installed upon the next start.
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def installPackage(self, filename: str) -> None:
|
def installPackage(self, filename: str) -> None:
|
||||||
# Get package information
|
|
||||||
package_info = self.getPackageInfo(filename)
|
|
||||||
package_id = package_info["package_id"]
|
|
||||||
|
|
||||||
has_changes = False
|
has_changes = False
|
||||||
# Check the delayed installation and removal lists first
|
try:
|
||||||
if package_id in self._to_remove_package_set:
|
# Get package information
|
||||||
self._to_remove_package_set.remove(package_id)
|
package_info = self.getPackageInfo(filename)
|
||||||
has_changes = True
|
package_id = package_info["package_id"]
|
||||||
|
|
||||||
# Check if it is installed
|
# Check the delayed installation and removal lists first
|
||||||
installed_package_info = self.getInstalledPackageInfo(package_info["package_id"])
|
if package_id in self._to_remove_package_set:
|
||||||
to_install_package = installed_package_info is None # Install if the package has not been installed
|
self._to_remove_package_set.remove(package_id)
|
||||||
if installed_package_info is not None:
|
has_changes = True
|
||||||
# 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
|
|
||||||
|
|
||||||
if to_install_package:
|
# Check if it is installed
|
||||||
Logger.log("i", "Package [%s] version [%s] is scheduled to be installed.",
|
installed_package_info = self.getInstalledPackageInfo(package_info["package_id"])
|
||||||
package_id, package_info["package_version"])
|
to_install_package = installed_package_info is None # Install if the package has not been installed
|
||||||
# Copy the file to cache dir so we don't need to rely on the original file to be present
|
if installed_package_info is not None:
|
||||||
package_cache_dir = os.path.join(os.path.abspath(Resources.getCacheStoragePath()), "cura_packages")
|
# Compare versions and only schedule the installation if the given package is newer
|
||||||
if not os.path.exists(package_cache_dir):
|
new_version = package_info["package_version"]
|
||||||
os.makedirs(package_cache_dir, exist_ok=True)
|
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")
|
if to_install_package:
|
||||||
shutil.copy2(filename, target_file_path)
|
# 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,
|
target_file_path = os.path.join(package_cache_dir, package_id + ".curapackage")
|
||||||
"filename": target_file_path}
|
shutil.copy2(filename, target_file_path)
|
||||||
has_changes = True
|
|
||||||
|
|
||||||
self._saveManagementData()
|
self._to_install_package_dict[package_id] = {"package_info": package_info,
|
||||||
if has_changes:
|
"filename": target_file_path}
|
||||||
self.installedPackagesChanged.emit()
|
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.
|
# Schedules the given package to be removed upon the next start.
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue