Welcome to mirror list, hosted at ThFree Co, Russian Federation.

VersionUpgrade50to52.py « VersionUpgrade50to52 « VersionUpgrade « plugins - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9011bc324326766ec463b834c428a749b409b94c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright (c) 2022 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.

import configparser
from typing import List, Tuple

from UM.VersionUpgrade import VersionUpgrade
from cura.PrinterOutput.PrinterOutputDevice import ConnectionType
from cura.Settings.CuraStackBuilder import CuraStackBuilder
from cura.Settings.GlobalStack import GlobalStack
from cura.Machines.ContainerTree import ContainerTree
from cura.CuraApplication import CuraApplication
import io


class VersionUpgrade50to52(VersionUpgrade):
    """
    Upgrades configurations from the state they were in at version 5.0 to the
    state they should be in at version 5.2.
    """

    def upgradeMachine(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
        """
        Upgrades container stacks to have the new version number.
        Upgrades container stacks for FLSun Racer to change their profiles.
        :param serialized: The original contents of the container stack.
        :param filename: The file name of the container stack.
        :return: A list of file names, and a list of the new contents for those files.
        """
        [filename], [serialized] = self.upgradeStack(serialized, filename)
        return [filename], [serialized]

        parser = configparser.ConfigParser(interpolation = None)
        parser.read_string(serialized)

        connection_types = []
        if "metadata" in parser and "connection_type" in parser["metadata"]:
            connection_types = [int(connection_type) for connection_type in parser["metadata"]["connection_type"].split(",")]

        cloud_connection_types = ConnectionType.NetworkConnection, ConnectionType.CloudConnection

        if not any(connection_type in cloud_connection_types for connection_type in connection_types):
            return [filename], [serialized]

        stack = GlobalStack("")
        stack.deserialize(serialized)
        definition_id = stack.getDefinition().getId()
        abstract_machine = CuraStackBuilder.createAbstractMachine(definition_id)

        if abstract_machine:
            abstract_machine_filename = abstract_machine_id
            abstract_machine_serialized = abstract_machine.serialize()
            return [filename, abstract_machine_filename], [serialized, abstract_machine_serialized]

        return [filename], [serialized]

    def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
        """
        Upgrades container stacks to have the new version number.
        Upgrades container stacks for FLSun Racer to change their profiles.
        :param serialized: The original contents of the container stack.
        :param filename: The file name of the container stack.
        :return: A list of file names, and a list of the new contents for those files.
        """

        parser = configparser.ConfigParser(interpolation = None)
        parser.read_string(serialized)

        parser["metadata"]["setting_version"] = "6000020"
        parser["general"]["version"] = "6"

        file = io.StringIO()
        parser.write(file)
        data = file.getvalue()

        return [filename], [data]