Correct the configparser

The import was missing. Also, the parser was not called on the correct stream.

Contributes to issue CURA-37.
This commit is contained in:
Ghostkeeper 2015-12-17 14:30:53 +01:00
parent 57f5e60fa5
commit f2a95ae89c

View file

@ -1,6 +1,7 @@
# Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
import configparser #For reading the legacy profile INI files.
import json #For reading the Dictionary of Doom.
from UM.Application import Application #To get the machine manager to create the new profile in.
@ -28,9 +29,13 @@ class LegacyProfileReader(ProfileReader):
profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False) #Create an empty profile.
profile.setName("Imported Legacy Profile")
stream = io.StringIO(serialised) #ConfigParser needs to read from a stream.
parser = configparser.ConfigParser(interpolation = None)
parser.readfp(stream)
try:
with open(file_name) as f:
parser.readfp(f) #Parse the INI file.
except Exception as e:
Logger.log("e", "Unable to open legacy profile %s: %s", file_name, str(e))
return None
#Legacy Cura saved the profile under the section "profile_N" where N is the ID of a machine, except when you export in which case it saves it in the section "profile".
#Since importing multiple machine profiles is out of scope, just import the first section we find.