mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-10 08:17:49 -06:00
Pass optional file_name for deserialization
CURA-4613 Some upgrades depend on the file_name, so the file_name is needed in this case.
This commit is contained in:
parent
1b76d08f01
commit
18c7a5acf3
4 changed files with 31 additions and 21 deletions
|
@ -348,8 +348,8 @@ class CuraContainerStack(ContainerStack):
|
||||||
#
|
#
|
||||||
# \throws InvalidContainerStackError Raised when no definition can be found for the stack.
|
# \throws InvalidContainerStackError Raised when no definition can be found for the stack.
|
||||||
@override(ContainerStack)
|
@override(ContainerStack)
|
||||||
def deserialize(self, contents: str) -> None:
|
def deserialize(self, contents: str, file_name: Optional[str] = None) -> None:
|
||||||
super().deserialize(contents)
|
super().deserialize(contents, file_name)
|
||||||
|
|
||||||
new_containers = self._containers.copy()
|
new_containers = self._containers.copy()
|
||||||
while len(new_containers) < len(_ContainerIndexes.IndexTypeMap):
|
while len(new_containers) < len(_ContainerIndexes.IndexTypeMap):
|
||||||
|
|
|
@ -92,8 +92,8 @@ class ExtruderStack(CuraContainerStack):
|
||||||
return self.getNextStack()._getMachineDefinition()
|
return self.getNextStack()._getMachineDefinition()
|
||||||
|
|
||||||
@override(CuraContainerStack)
|
@override(CuraContainerStack)
|
||||||
def deserialize(self, contents: str) -> None:
|
def deserialize(self, contents: str, file_name: Optional[str] = None) -> None:
|
||||||
super().deserialize(contents)
|
super().deserialize(contents, file_name)
|
||||||
stacks = ContainerRegistry.getInstance().findContainerStacks(id=self.getMetaDataEntry("machine", ""))
|
stacks = ContainerRegistry.getInstance().findContainerStacks(id=self.getMetaDataEntry("machine", ""))
|
||||||
if stacks:
|
if stacks:
|
||||||
self.setNextStack(stacks[0])
|
self.setNextStack(stacks[0])
|
||||||
|
|
|
@ -152,7 +152,8 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
|
|
||||||
if not definitions:
|
if not definitions:
|
||||||
definition_container = DefinitionContainer(container_id)
|
definition_container = DefinitionContainer(container_id)
|
||||||
definition_container.deserialize(archive.open(each_definition_container_file).read().decode("utf-8"))
|
definition_container.deserialize(archive.open(each_definition_container_file).read().decode("utf-8"),
|
||||||
|
file_name = each_definition_container_file)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
definition_container = definitions[0]
|
definition_container = definitions[0]
|
||||||
|
@ -208,7 +209,8 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
instance_container = InstanceContainer(container_id)
|
instance_container = InstanceContainer(container_id)
|
||||||
|
|
||||||
# Deserialize InstanceContainer by converting read data from bytes to string
|
# Deserialize InstanceContainer by converting read data from bytes to string
|
||||||
instance_container.deserialize(archive.open(each_instance_container_file).read().decode("utf-8"))
|
instance_container.deserialize(archive.open(each_instance_container_file).read().decode("utf-8"),
|
||||||
|
file_name = each_instance_container_file)
|
||||||
instance_container_list.append(instance_container)
|
instance_container_list.append(instance_container)
|
||||||
|
|
||||||
container_type = instance_container.getMetaDataEntry("type")
|
container_type = instance_container.getMetaDataEntry("type")
|
||||||
|
@ -378,7 +380,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
return WorkspaceReader.PreReadResult.accepted
|
return WorkspaceReader.PreReadResult.accepted
|
||||||
|
|
||||||
## Overrides an ExtruderStack in the given GlobalStack and returns the new ExtruderStack.
|
## Overrides an ExtruderStack in the given GlobalStack and returns the new ExtruderStack.
|
||||||
def _overrideExtruderStack(self, global_stack, extruder_file_content):
|
def _overrideExtruderStack(self, global_stack, extruder_file_content, extruder_stack_file):
|
||||||
# Get extruder position first
|
# Get extruder position first
|
||||||
extruder_config = configparser.ConfigParser()
|
extruder_config = configparser.ConfigParser()
|
||||||
extruder_config.read_string(extruder_file_content)
|
extruder_config.read_string(extruder_file_content)
|
||||||
|
@ -394,7 +396,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Override the given extruder stack
|
# Override the given extruder stack
|
||||||
extruder_stack.deserialize(extruder_file_content)
|
extruder_stack.deserialize(extruder_file_content, file_name = extruder_stack_file)
|
||||||
|
|
||||||
# return the new ExtruderStack
|
# return the new ExtruderStack
|
||||||
return extruder_stack
|
return extruder_stack
|
||||||
|
@ -484,7 +486,8 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
definitions = self._container_registry.findDefinitionContainers(id = container_id)
|
definitions = self._container_registry.findDefinitionContainers(id = container_id)
|
||||||
if not definitions:
|
if not definitions:
|
||||||
definition_container = DefinitionContainer(container_id)
|
definition_container = DefinitionContainer(container_id)
|
||||||
definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"))
|
definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"),
|
||||||
|
file_name = definition_container_file)
|
||||||
self._container_registry.addContainer(definition_container)
|
self._container_registry.addContainer(definition_container)
|
||||||
Job.yieldThread()
|
Job.yieldThread()
|
||||||
|
|
||||||
|
@ -502,18 +505,21 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
|
|
||||||
if not materials:
|
if not materials:
|
||||||
material_container = xml_material_profile(container_id)
|
material_container = xml_material_profile(container_id)
|
||||||
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
|
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"),
|
||||||
|
file_name = material_container_file)
|
||||||
containers_to_add.append(material_container)
|
containers_to_add.append(material_container)
|
||||||
else:
|
else:
|
||||||
material_container = materials[0]
|
material_container = materials[0]
|
||||||
if not material_container.isReadOnly(): # Only create new materials if they are not read only.
|
if not material_container.isReadOnly(): # Only create new materials if they are not read only.
|
||||||
if self._resolve_strategies["material"] == "override":
|
if self._resolve_strategies["material"] == "override":
|
||||||
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
|
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"),
|
||||||
|
file_name = material_container_file)
|
||||||
elif self._resolve_strategies["material"] == "new":
|
elif self._resolve_strategies["material"] == "new":
|
||||||
# Note that we *must* deserialize it with a new ID, as multiple containers will be
|
# Note that we *must* deserialize it with a new ID, as multiple containers will be
|
||||||
# auto created & added.
|
# auto created & added.
|
||||||
material_container = xml_material_profile(self.getNewId(container_id))
|
material_container = xml_material_profile(self.getNewId(container_id))
|
||||||
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
|
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"),
|
||||||
|
file_name = material_container_file)
|
||||||
containers_to_add.append(material_container)
|
containers_to_add.append(material_container)
|
||||||
|
|
||||||
material_containers.append(material_container)
|
material_containers.append(material_container)
|
||||||
|
@ -540,7 +546,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
instance_container = InstanceContainer(container_id)
|
instance_container = InstanceContainer(container_id)
|
||||||
|
|
||||||
# Deserialize InstanceContainer by converting read data from bytes to string
|
# Deserialize InstanceContainer by converting read data from bytes to string
|
||||||
instance_container.deserialize(serialized)
|
instance_container.deserialize(serialized, file_name = instance_container_file)
|
||||||
container_type = instance_container.getMetaDataEntry("type")
|
container_type = instance_container.getMetaDataEntry("type")
|
||||||
Job.yieldThread()
|
Job.yieldThread()
|
||||||
|
|
||||||
|
@ -562,7 +568,8 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
else:
|
else:
|
||||||
if self._resolve_strategies["machine"] == "override" or self._resolve_strategies["machine"] is None:
|
if self._resolve_strategies["machine"] == "override" or self._resolve_strategies["machine"] is None:
|
||||||
instance_container = user_containers[0]
|
instance_container = user_containers[0]
|
||||||
instance_container.deserialize(archive.open(instance_container_file).read().decode("utf-8"))
|
instance_container.deserialize(archive.open(instance_container_file).read().decode("utf-8"),
|
||||||
|
file_name = instance_container_file)
|
||||||
instance_container.setDirty(True)
|
instance_container.setDirty(True)
|
||||||
elif self._resolve_strategies["machine"] == "new":
|
elif self._resolve_strategies["machine"] == "new":
|
||||||
# The machine is going to get a spiffy new name, so ensure that the id's of user settings match.
|
# The machine is going to get a spiffy new name, so ensure that the id's of user settings match.
|
||||||
|
@ -595,7 +602,8 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
# selected strategy.
|
# selected strategy.
|
||||||
if self._resolve_strategies[container_type] == "override":
|
if self._resolve_strategies[container_type] == "override":
|
||||||
instance_container = changes_containers[0]
|
instance_container = changes_containers[0]
|
||||||
instance_container.deserialize(archive.open(instance_container_file).read().decode("utf-8"))
|
instance_container.deserialize(archive.open(instance_container_file).read().decode("utf-8"),
|
||||||
|
file_name = instance_container_file)
|
||||||
instance_container.setDirty(True)
|
instance_container.setDirty(True)
|
||||||
|
|
||||||
elif self._resolve_strategies[container_type] == "new":
|
elif self._resolve_strategies[container_type] == "new":
|
||||||
|
@ -656,7 +664,8 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
# There is a machine, check if it has authentication data. If so, keep that data.
|
# There is a machine, check if it has authentication data. If so, keep that data.
|
||||||
network_authentication_id = container_stacks[0].getMetaDataEntry("network_authentication_id")
|
network_authentication_id = container_stacks[0].getMetaDataEntry("network_authentication_id")
|
||||||
network_authentication_key = container_stacks[0].getMetaDataEntry("network_authentication_key")
|
network_authentication_key = container_stacks[0].getMetaDataEntry("network_authentication_key")
|
||||||
container_stacks[0].deserialize(archive.open(global_stack_file).read().decode("utf-8"))
|
container_stacks[0].deserialize(archive.open(global_stack_file).read().decode("utf-8"),
|
||||||
|
file_name = global_stack_file)
|
||||||
if network_authentication_id:
|
if network_authentication_id:
|
||||||
container_stacks[0].addMetaDataEntry("network_authentication_id", network_authentication_id)
|
container_stacks[0].addMetaDataEntry("network_authentication_id", network_authentication_id)
|
||||||
if network_authentication_key:
|
if network_authentication_key:
|
||||||
|
@ -666,7 +675,8 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
# create a new global stack
|
# create a new global stack
|
||||||
stack = GlobalStack(global_stack_id_new)
|
stack = GlobalStack(global_stack_id_new)
|
||||||
# Deserialize stack by converting read data from bytes to string
|
# Deserialize stack by converting read data from bytes to string
|
||||||
stack.deserialize(archive.open(global_stack_file).read().decode("utf-8"))
|
stack.deserialize(archive.open(global_stack_file).read().decode("utf-8"),
|
||||||
|
file_name = global_stack_file)
|
||||||
|
|
||||||
# Ensure a unique ID and name
|
# Ensure a unique ID and name
|
||||||
stack._id = global_stack_id_new
|
stack._id = global_stack_id_new
|
||||||
|
@ -706,7 +716,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
if self._resolve_strategies["machine"] == "override":
|
if self._resolve_strategies["machine"] == "override":
|
||||||
if global_stack.getProperty("machine_extruder_count", "value") > 1:
|
if global_stack.getProperty("machine_extruder_count", "value") > 1:
|
||||||
# deserialize new extruder stack over the current ones (if any)
|
# deserialize new extruder stack over the current ones (if any)
|
||||||
stack = self._overrideExtruderStack(global_stack, extruder_file_content)
|
stack = self._overrideExtruderStack(global_stack, extruder_file_content, extruder_stack_file)
|
||||||
if stack is None:
|
if stack is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -726,7 +736,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
extruder_config.write(tmp_string_io)
|
extruder_config.write(tmp_string_io)
|
||||||
extruder_file_content = tmp_string_io.getvalue()
|
extruder_file_content = tmp_string_io.getvalue()
|
||||||
|
|
||||||
stack.deserialize(extruder_file_content)
|
stack.deserialize(extruder_file_content, file_name = extruder_stack_file)
|
||||||
|
|
||||||
# Ensure a unique ID and name
|
# Ensure a unique ID and name
|
||||||
stack._id = new_id
|
stack._id = new_id
|
||||||
|
|
|
@ -422,11 +422,11 @@ class XmlMaterialProfile(InstanceContainer):
|
||||||
return version * 1000000 + setting_version
|
return version * 1000000 + setting_version
|
||||||
|
|
||||||
## Overridden from InstanceContainer
|
## Overridden from InstanceContainer
|
||||||
def deserialize(self, serialized):
|
def deserialize(self, serialized, file_name = None):
|
||||||
containers_to_add = []
|
containers_to_add = []
|
||||||
# update the serialized data first
|
# update the serialized data first
|
||||||
from UM.Settings.Interfaces import ContainerInterface
|
from UM.Settings.Interfaces import ContainerInterface
|
||||||
serialized = ContainerInterface.deserialize(self, serialized)
|
serialized = ContainerInterface.deserialize(self, serialized, file_name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = ET.fromstring(serialized)
|
data = ET.fromstring(serialized)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue