Use optional arg in serialize() to exclude network auth keys

CURA-4049
This commit is contained in:
Lipu Fei 2017-07-17 11:04:06 +02:00
parent 7f1dfcf433
commit 68989f2871
2 changed files with 10 additions and 11 deletions

View file

@ -69,7 +69,7 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter):
# \param archive The archive to write to. # \param archive The archive to write to.
@staticmethod @staticmethod
def _writeContainerToArchive(container, archive): def _writeContainerToArchive(container, archive):
if type(container) == type(ContainerRegistry.getInstance().getEmptyInstanceContainer()): if isinstance(container, type(ContainerRegistry.getInstance().getEmptyInstanceContainer())):
return # Empty file, do nothing. return # Empty file, do nothing.
file_suffix = ContainerRegistry.getMimeTypeForContainer(type(container)).preferredSuffix file_suffix = ContainerRegistry.getMimeTypeForContainer(type(container)).preferredSuffix
@ -87,14 +87,9 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter):
file_in_archive = zipfile.ZipInfo(file_name) file_in_archive = zipfile.ZipInfo(file_name)
# For some reason we have to set the compress type of each file as well (it doesn't keep the type of the entire archive) # For some reason we have to set the compress type of each file as well (it doesn't keep the type of the entire archive)
file_in_archive.compress_type = zipfile.ZIP_DEFLATED file_in_archive.compress_type = zipfile.ZIP_DEFLATED
if type(container) == ContainerStack and (container.getMetaDataEntry("network_authentication_id") or container.getMetaDataEntry("network_authentication_key")):
# TODO: Hack # Do not include the network authentication keys
# Create a shallow copy of the container, so we can filter out the network auth (if any) ignore_keys = ["network_authentication_id", "network_authentication_key"]
container_copy = copy.deepcopy(container) serialized_data = container.serialize(ignore_metadata_keys = ignore_keys)
container_copy.removeMetaDataEntry("network_authentication_id")
container_copy.removeMetaDataEntry("network_authentication_key")
serialized_data = container_copy.serialize()
else:
serialized_data = container.serialize()
archive.writestr(file_in_archive, serialized_data) archive.writestr(file_in_archive, serialized_data)

View file

@ -109,7 +109,7 @@ class XmlMaterialProfile(InstanceContainer):
## Overridden from InstanceContainer ## Overridden from InstanceContainer
# base file: common settings + supported machines # base file: common settings + supported machines
# machine / variant combination: only changes for itself. # machine / variant combination: only changes for itself.
def serialize(self): def serialize(self, ignore_metadata_keys=[]):
registry = ContainerRegistry.getInstance() registry = ContainerRegistry.getInstance()
base_file = self.getMetaDataEntry("base_file", "") base_file = self.getMetaDataEntry("base_file", "")
@ -129,6 +129,10 @@ class XmlMaterialProfile(InstanceContainer):
builder.start("metadata") builder.start("metadata")
metadata = copy.deepcopy(self.getMetaData()) metadata = copy.deepcopy(self.getMetaData())
# remove the keys that we want to ignore in the metadata
for key in ignore_metadata_keys:
if key in metadata:
del metadata[key]
properties = metadata.pop("properties", {}) properties = metadata.pop("properties", {})
# Metadata properties that should not be serialized. # Metadata properties that should not be serialized.