mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-29 07:14:24 +08:00
Merge pull request #5999 from Ultimaker/CURA-6659_fix_import_quality
CURA-6659 Use VersionUpgradeManager to update the imported quality
This commit is contained in:
commit
e8350547b7
@ -8,6 +8,7 @@ from UM.PluginRegistry import PluginRegistry
|
|||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Settings.ContainerFormatError import ContainerFormatError
|
from UM.Settings.ContainerFormatError import ContainerFormatError
|
||||||
from UM.Settings.InstanceContainer import InstanceContainer # The new profile to make.
|
from UM.Settings.InstanceContainer import InstanceContainer # The new profile to make.
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
from cura.ReaderWriters.ProfileReader import ProfileReader
|
from cura.ReaderWriters.ProfileReader import ProfileReader
|
||||||
|
|
||||||
import zipfile
|
import zipfile
|
||||||
@ -67,9 +68,10 @@ class CuraProfileReader(ProfileReader):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
version = int(parser["general"]["version"])
|
version = int(parser["general"]["version"])
|
||||||
|
setting_version = int(parser["metadata"].get("setting_version", 0))
|
||||||
if InstanceContainer.Version != version:
|
if InstanceContainer.Version != version:
|
||||||
name = parser["general"]["name"]
|
name = parser["general"]["name"]
|
||||||
return self._upgradeProfileVersion(serialized, name, version)
|
return self._upgradeProfileVersion(serialized, name, version, setting_version)
|
||||||
else:
|
else:
|
||||||
return [(serialized, profile_id)]
|
return [(serialized, profile_id)]
|
||||||
|
|
||||||
@ -98,19 +100,24 @@ class CuraProfileReader(ProfileReader):
|
|||||||
# \param profile_id The name of the profile.
|
# \param profile_id The name of the profile.
|
||||||
# \param source_version The profile version of 'serialized'.
|
# \param source_version The profile version of 'serialized'.
|
||||||
# \return List of serialized profile strings and matching profile names.
|
# \return List of serialized profile strings and matching profile names.
|
||||||
def _upgradeProfileVersion(self, serialized: str, profile_id: str, source_version: int) -> List[Tuple[str, str]]:
|
def _upgradeProfileVersion(self, serialized: str, profile_id: str, main_version: int, setting_version: int) -> List[Tuple[str, str]]:
|
||||||
converter_plugins = PluginRegistry.getInstance().getAllMetaData(filter = {"version_upgrade": {} }, active_only = True)
|
source_version = main_version * 1000000 + setting_version
|
||||||
|
|
||||||
source_format = ("profile", source_version)
|
from UM.VersionUpgradeManager import VersionUpgradeManager
|
||||||
profile_convert_funcs = [plugin["version_upgrade"][source_format][2] for plugin in converter_plugins
|
results = VersionUpgradeManager.getInstance().updateFilesData("quality_changes", source_version, [serialized], [profile_id])
|
||||||
if source_format in plugin["version_upgrade"] and plugin["version_upgrade"][source_format][1] == InstanceContainer.Version]
|
serialized = results.files_data[0]
|
||||||
|
|
||||||
if not profile_convert_funcs:
|
parser = configparser.ConfigParser(interpolation = None)
|
||||||
Logger.log("w", "Unable to find an upgrade path for the profile [%s]", profile_id)
|
parser.read_string(serialized)
|
||||||
|
if "general" not in parser:
|
||||||
|
Logger.log("w", "Missing required section 'general'.")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
filenames, outputs = profile_convert_funcs[0](serialized, profile_id)
|
new_source_version = results.version
|
||||||
if filenames is None and outputs is None:
|
if int(new_source_version / 1000000) != InstanceContainer.Version or new_source_version % 1000000 != CuraApplication.SettingVersion:
|
||||||
Logger.log("w", "The conversion failed to return any usable data for [%s]", profile_id)
|
Logger.log("e", "Failed to upgrade profile [%s]", profile_id)
|
||||||
|
|
||||||
|
if int(parser["general"]["version"]) != InstanceContainer.Version:
|
||||||
|
Logger.log("e", "Failed to upgrade profile [%s]", profile_id)
|
||||||
return []
|
return []
|
||||||
return list(zip(outputs, filenames))
|
return [(serialized, profile_id)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user