Make version upgrade also translate file names

This was required since Cura 2.1 produced files with the same filename (bar extension). This then resulted in two containers with the same ID. If you had bad luck, an instance container was chosen as global container (depending on which was first in the unordered dictionary). This gives the current settings the postfix _current_settings, fixing that issue.

Contributes to issue CURA-844.
This commit is contained in:
Ghostkeeper 2016-07-07 15:13:58 +02:00
parent 1b0974ba9f
commit e6efba3868
No known key found for this signature in database
GPG key ID: 701948C5954A7385
4 changed files with 55 additions and 34 deletions

View file

@ -10,10 +10,11 @@ import UM.VersionUpgrade
# of the file format.
#
# \param serialised The serialised form of a profile in version 1.
# \param filename The supposed filename of the profile.
# \return A profile instance, or None if the file format is incorrect.
def importFrom(serialised):
def importFrom(serialised, filename):
try:
return Profile(serialised)
return Profile(serialised, filename)
except (configparser.Error, UM.VersionUpgrade.FormatException, UM.VersionUpgrade.InvalidVersionException):
return None
@ -22,8 +23,11 @@ def importFrom(serialised):
class Profile:
## Reads version 1 of the file format, storing it in memory.
#
# \param serialised A string with the contents of a machine instance file.
def __init__(self, serialised):
# \param serialised A string with the contents of a profile.
# \param filename The supposed filename of the profile.
def __init__(self, serialised, filename):
self._filename = filename
parser = configparser.ConfigParser(interpolation = None)
parser.read_string(serialised)
@ -70,11 +74,14 @@ class Profile:
## Serialises this profile as file format version 2.
#
# \return A serialised form of this profile, serialised in version 2 of
# the file format.
# \return A tuple containing the new filename and a serialised form of
# this profile, serialised in version 2 of the file format.
def export(self):
import VersionUpgrade21to22 # Import here to prevent circular dependencies.
if self._name == "Current settings":
self._filename += "_current_settings" #This resolves a duplicate ID arising from how Cura 2.1 stores its current settings.
config = configparser.ConfigParser(interpolation = None)
config.add_section("general")
@ -123,4 +130,4 @@ class Profile:
output = io.StringIO()
config.write(output)
return output.getvalue()
return self._filename, output.getvalue()