<commit_before>from UM.Workspace.WorkspaceReader import WorkspaceReader
from UM.Application import Application

from UM.Logger import Logger

##    Base implementation for reading 3MF workspace files.
class ThreeMFWorkspaceReader(WorkspaceReader):
    def __init__(self):
        super().__init__()
        self._supported_extensions = [".3mf"]

        self._3mf_mesh_reader = None

    def preRead(self, file_name):
        self._3mf_mesh_reader = Application.getInstance().getMeshFileHandler().getReaderForFile(file_name)
        if self._3mf_mesh_reader and self._3mf_mesh_reader.preRead(file_name) == WorkspaceReader.PreReadResult.accepted:
            pass
        else:
            Logger.log("w", "Could not find reader that was able to read the scene data for 3MF workspace")
            return WorkspaceReader.PreReadResult.failed
        # TODO: Ask user if it's  okay for the scene to be cleared
        return WorkspaceReader.PreReadResult.accepted

    def read(self, file_name):
        pass<commit_msg>Stacks are now loaded from workspace file<commit_after>from UM.Workspace.WorkspaceReader import WorkspaceReader
from UM.Application import Application

from UM.Logger import Logger
from UM.Settings.ContainerStack import ContainerStack

import zipfile

##    Base implementation for reading 3MF workspace files.
class ThreeMFWorkspaceReader(WorkspaceReader):
    def __init__(self):
        super().__init__()
        self._supported_extensions = [".3mf"]

        self._3mf_mesh_reader = None

    def preRead(self, file_name):
        self._3mf_mesh_reader = Application.getInstance().getMeshFileHandler().getReaderForFile(file_name)
        if self._3mf_mesh_reader and self._3mf_mesh_reader.preRead(file_name) == WorkspaceReader.PreReadResult.accepted:
            pass
        else:
            Logger.log("w", "Could not find reader that was able to read the scene data for 3MF workspace")
            return WorkspaceReader.PreReadResult.failed
        # TODO: Ask user if it's  okay for the scene to be cleared
        return WorkspaceReader.PreReadResult.accepted

    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/")]

        # Get the stack(s) saved in the workspace.
        container_stack_files = [name for name in cura_file_names if name.endswith(".stack.cfg")]
        global_stack = None
        extruder_stacks = []
        for container_stack_file in container_stack_files:
            container_id = container_stack_file.replace("Cura/", "")
            container_id = container_id.replace(".stack.cfg", "")
            stack = ContainerStack(container_id)

            # Serialize stack by converting read data from bytes to string
            stack.deserialize(archive.open(container_stack_file).read().decode("utf-8"))

            if stack.getMetaDataEntry("type") == "extruder_train":
                extruder_stacks.append(stack)
            else:
                global_stack = stack

        # Check if the right machine type is active now
        #Application.getInstance().getGlobalContainerStack().getBottom().getId() ==


        return nodes
{'fraction_non_alphanumeric': 0.08061647895672792, 'fraction_numerical': 0.004742145820983995, 'mean_word_length': 2.9846517119244393, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5820721', 'n_tokens_mistral': 921, 'n_tokens_neox': 901, 'n_words': 246}