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

VersionUpgrade35to40.py « VersionUpgrade35to40 « VersionUpgrade « plugins - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 85a7e3135a4a0d85d6744eea86a3c8474d163f21 (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
import configparser
from typing import Tuple, List, Set, Dict
import io

from UM.VersionUpgrade import VersionUpgrade
from cura.PrinterOutput.PrinterOutputDevice import ConnectionType

deleted_settings = {"bridge_wall_max_overhang"}  # type: Set[str]
renamed_configurations = {"connect_group_name": "group_name"}  # type: Dict[str, str]


class VersionUpgrade35to40(VersionUpgrade):
    #  Upgrades stacks to have the new version number.
    def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
        parser = configparser.ConfigParser(interpolation=None)
        parser.read_string(serialized)

        # Update version number.
        parser["general"]["version"] = "4"
        parser["metadata"]["setting_version"] = "6"

        if parser["metadata"].get("um_network_key") is not None or parser["metadata"].get("octoprint_api_key") is not None:
            # Set the connection type if um_network_key or the octoprint key is set.
            parser["metadata"]["connection_type"] = str(ConnectionType.NetworkConnection.value)

        if "metadata" in parser:
            for old_name, new_name in renamed_configurations.items():
                if old_name not in parser["metadata"]:
                    continue
                parser["metadata"][new_name] = parser["metadata"][old_name]
                del parser["metadata"][old_name]

        result = io.StringIO()
        parser.write(result)
        return [filename], [result.getvalue()]

    def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
        """Upgrades Preferences to have the new version number."""

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

        if "metadata" not in parser:
            parser["metadata"] = {}
        parser["general"]["version"] = "6"
        parser["metadata"]["setting_version"] = "6"

        result = io.StringIO()
        parser.write(result)
        return [filename], [result.getvalue()]

    def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
        """Upgrades instance containers to have the new version number."""

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

        # Update version number.
        parser["general"]["version"] = "4"
        parser["metadata"]["setting_version"] = "6"

        #self._resetConcentric3DInfillPattern(parser)
        if "values" in parser:
            for deleted_setting in deleted_settings:
                if deleted_setting not in parser["values"]:
                    continue
                del parser["values"][deleted_setting]

        result = io.StringIO()
        parser.write(result)
        return [filename], [result.getvalue()]