This commit is contained in:
ChrisTerBeke 2018-05-02 13:25:53 +02:00
commit 9ce3bc3806
5 changed files with 51 additions and 48 deletions

View File

@ -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"])
@ -93,19 +95,16 @@ 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():
for package in packages:
if package["package_id"] == package_id:
package_info = package
return package_info
return package
return None
@ -113,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.
@ -184,11 +183,12 @@ class CuraPackageManager(QObject):
# Schedules the given package file to be installed upon the next start.
@pyqtSlot(str)
def installPackage(self, filename: str) -> None:
has_changes = False
try:
# 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)
@ -207,6 +207,8 @@ class CuraPackageManager(QObject):
to_install_package = True
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
@ -220,7 +222,9 @@ class CuraPackageManager(QObject):
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()

View File

@ -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

View File

@ -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"],

View File

@ -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.
#