本文整理汇总了Python中UM.Settings.ContainerStack.ContainerStack.deserialize方法的典型用法代码示例。如果您正苦于以下问题:Python ContainerStack.deserialize方法的具体用法?Python ContainerStack.deserialize怎么用?Python ContainerStack.deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.Settings.ContainerStack.ContainerStack
的用法示例。
在下文中一共展示了ContainerStack.deserialize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_roundtrip_stack
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import deserialize [as 别名]
def test_roundtrip_stack(tmpdir, process_count, loaded_container_registry):
definition = loaded_container_registry.findDefinitionContainers(id = "multiple_settings")[0]
instances = loaded_container_registry.findInstanceContainers(id = "setting_values")[0]
container_stack = ContainerStack("test_stack")
container_stack.setName("Test Container Stack")
container_stack.addMetaDataEntry("test", "test")
container_stack.addContainer(definition)
container_stack.addContainer(instances)
temp_file = tmpdir.join("container_stack_test")
mp_run(process_count, write_data, temp_file, container_stack)
assert len(list(tmpdir.listdir())) == 1
results = mp_run(process_count, read_data, temp_file)
for result in results:
deserialized_stack = ContainerStack("test_stack")
deserialized_stack.deserialize(result)
assert deserialized_stack.getName() == container_stack.getName()
assert deserialized_stack.getMetaData() == container_stack.getMetaData()
assert deserialized_stack.getBottom() == container_stack.getBottom()
assert deserialized_stack.getTop() == container_stack.getTop()
示例2: _test_serialize_cycle
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import deserialize [as 别名]
def _test_serialize_cycle(container_stack):
name = container_stack.getName()
metadata = container_stack.getMetaData()
containers = container_stack.getContainers()
serialised = container_stack.serialize()
container_stack = ContainerStack(uuid.uuid4().int) # Completely fresh container stack.
container_stack.deserialize(serialised)
#ID and nextStack are allowed to be different.
assert name == container_stack.getName()
assert metadata == container_stack.getMetaData()
assert containers == container_stack.getContainers()
示例3: test_serialize
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import deserialize [as 别名]
def test_serialize(container_stack):
registry = ContainerRegistry.getInstance() # All containers need to be registered in order to be recovered again after deserialising.
# First test the empty container stack.
_test_serialize_cycle(container_stack)
# Case with one subcontainer.
container = InstanceContainer(str(uuid.uuid4()))
registry.addContainer(container)
container_stack.addContainer(container)
_test_serialize_cycle(container_stack)
# Case with two subcontainers.
container = InstanceContainer(str(uuid.uuid4()))
registry.addContainer(container)
container_stack.addContainer(container) # Already had one, if all previous assertions were correct.
_test_serialize_cycle(container_stack)
# Case with all types of subcontainers.
container = DefinitionContainer(str(uuid.uuid4()))
registry.addContainer(container)
container_stack.addContainer(container)
container = ContainerStack(str(uuid.uuid4()))
registry.addContainer(container)
container_stack.addContainer(container)
_test_serialize_cycle(container_stack)
# With some metadata.
container_stack.getMetaData()["foo"] = "bar"
_test_serialize_cycle(container_stack)
# With a changed name.
container_stack.setName("Fred")
_test_serialize_cycle(container_stack)
# A name with special characters, to test the encoding.
container_stack.setName("ルベン")
_test_serialize_cycle(container_stack)
# Just to bully the one who implements this, a name with special characters in JSON and CFG.
container_stack.setName("=,\"")
_test_serialize_cycle(container_stack)
# A container that is not in the registry.
container_stack.addContainer(DefinitionContainer(str(uuid.uuid4())))
serialised = container_stack.serialize()
container_stack = ContainerStack(str(uuid.uuid4())) # Completely fresh container stack.
with pytest.raises(Exception):
container_stack.deserialize(serialised)
示例4: _test_serialize_cycle
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import deserialize [as 别名]
def _test_serialize_cycle(container_stack, ignored_metadata_keys: Optional[set] = None):
metadata = {key: value for key, value in container_stack.getMetaData().items()}
containers = container_stack.getContainers()
serialised = container_stack.serialize(ignored_metadata_keys = ignored_metadata_keys)
container_stack = ContainerStack(str(uuid.uuid4())) # Completely fresh container stack.
container_stack.deserialize(serialised)
# Remove ignored keys from metadata dict
if ignored_metadata_keys:
for key in ignored_metadata_keys:
if key in metadata:
del metadata[key]
# ID and nextStack are allowed to be different.
assert metadata.items() <= container_stack.getMetaData().items()
assert containers == container_stack.getContainers()
示例5: read
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import deserialize [as 别名]
def read(self, file_name):
# Load all the nodes / meshdata of the workspace
nodes = self._3mf_mesh_reader.read(file_name)
if nodes is None:
nodes = []
archive = zipfile.ZipFile(file_name, "r")
cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")]
# Create a shadow copy of the preferences (we don't want all of the preferences, but we do want to re-use its
# parsing code.
temp_preferences = Preferences()
temp_preferences.readFromFile(io.TextIOWrapper(archive.open("Cura/preferences.cfg"))) # We need to wrap it, else the archive parser breaks.
# Copy a number of settings from the temp preferences to the global
global_preferences = Preferences.getInstance()
global_preferences.setValue("general/visible_settings", temp_preferences.getValue("general/visible_settings"))
global_preferences.setValue("cura/categories_expanded", temp_preferences.getValue("cura/categories_expanded"))
Application.getInstance().expandedCategoriesChanged.emit() # Notify the GUI of the change
self._id_mapping = {}
# We don't add containers right away, but wait right until right before the stack serialization.
# We do this so that if something goes wrong, it's easier to clean up.
containers_to_add = []
# TODO: For the moment we use pretty naive existence checking. If the ID is the same, we assume in quite a few
# TODO: cases that the container loaded is the same (most notable in materials & definitions).
# TODO: It might be possible that we need to add smarter checking in the future.
Logger.log("d", "Workspace loading is checking definitions...")
# Get all the definition files & check if they exist. If not, add them.
definition_container_files = [name for name in cura_file_names if name.endswith(self._definition_container_suffix)]
for definition_container_file in definition_container_files:
container_id = self._stripFileToId(definition_container_file)
definitions = self._container_registry.findDefinitionContainers(id=container_id)
if not definitions:
definition_container = DefinitionContainer(container_id)
definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"))
self._container_registry.addContainer(definition_container)
Logger.log("d", "Workspace loading is checking materials...")
material_containers = []
# Get all the material files and check if they exist. If not, add them.
xml_material_profile = self._getXmlProfileClass()
if self._material_container_suffix is None:
self._material_container_suffix = ContainerRegistry.getMimeTypeForContainer(xml_material_profile).suffixes[0]
if xml_material_profile:
material_container_files = [name for name in cura_file_names if name.endswith(self._material_container_suffix)]
for material_container_file in material_container_files:
container_id = self._stripFileToId(material_container_file)
materials = self._container_registry.findInstanceContainers(id=container_id)
if not materials:
material_container = xml_material_profile(container_id)
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
containers_to_add.append(material_container)
else:
if not materials[0].isReadOnly(): # Only create new materials if they are not read only.
if self._resolve_strategies["material"] == "override":
materials[0].deserialize(archive.open(material_container_file).read().decode("utf-8"))
elif self._resolve_strategies["material"] == "new":
# Note that we *must* deserialize it with a new ID, as multiple containers will be
# auto created & added.
material_container = xml_material_profile(self.getNewId(container_id))
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
containers_to_add.append(material_container)
material_containers.append(material_container)
Logger.log("d", "Workspace loading is checking instance containers...")
# Get quality_changes and user profiles saved in the workspace
instance_container_files = [name for name in cura_file_names if name.endswith(self._instance_container_suffix)]
user_instance_containers = []
quality_changes_instance_containers = []
for instance_container_file in instance_container_files:
container_id = self._stripFileToId(instance_container_file)
instance_container = InstanceContainer(container_id)
# Deserialize InstanceContainer by converting read data from bytes to string
instance_container.deserialize(archive.open(instance_container_file).read().decode("utf-8"))
container_type = instance_container.getMetaDataEntry("type")
if container_type == "user":
# Check if quality changes already exists.
user_containers = self._container_registry.findInstanceContainers(id=container_id)
if not user_containers:
containers_to_add.append(instance_container)
else:
if self._resolve_strategies["machine"] == "override":
user_containers[0].deserialize(archive.open(instance_container_file).read().decode("utf-8"))
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.
extruder_id = instance_container.getMetaDataEntry("extruder", None)
if extruder_id:
new_id = self.getNewId(extruder_id) + "_current_settings"
instance_container._id = new_id
instance_container.setName(new_id)
instance_container.setMetaDataEntry("extruder", self.getNewId(extruder_id))
containers_to_add.append(instance_container)
machine_id = instance_container.getMetaDataEntry("machine", None)
if machine_id:
#.........这里部分代码省略.........
示例6: test_deserialize_containers
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import deserialize [as 别名]
def test_deserialize_containers(container_stack, container_registry):
container = InstanceContainer("a")
container_registry.addContainer(container)
serialised = """
[general]
name = Test
id = testid
version = {version}
[containers]
0 = a
""".format(version = ContainerStack.Version) # Test case where there is a container.
container_stack.deserialize(serialised)
assert container_stack.getContainers() == [container]
container_stack = ContainerStack(str(uuid.uuid4()))
serialised = """
[general]
name = Test
id = testid
version = {version}
[containers]
""".format(version = ContainerStack.Version) # Test case where there is no container.
container_stack.deserialize(serialised)
assert container_stack.getContainers() == []
container_stack = ContainerStack(str(uuid.uuid4()))
serialised = """
[general]
name = Test
id = testid
version = {version}
[containers]
0 = a
1 = a
""".format(version = ContainerStack.Version) # Test case where there are two of the same containers.
container_stack.deserialize(serialised)
assert container_stack.getContainers() == [container, container]
container_stack = ContainerStack(str(uuid.uuid4()))
serialised = """
[general]
name = Test
id = testid
version = {version}
[containers]
0 = a
1 = b
""".format(version = ContainerStack.Version) # Test case where a container doesn't exist.
with pytest.raises(Exception):
container_stack.deserialize(serialised)
container_stack = ContainerStack(str(uuid.uuid4()))
container_b = InstanceContainer("b") # Add the missing container and try again.
ContainerRegistry.getInstance().addContainer(container_b)
container_stack.deserialize(serialised)
assert container_stack.getContainers() == [container, container_b]