Fix references to exception classes

These were moved to VersionUpgrade module.

Contributes to issue CURA-844.
This commit is contained in:
Ghostkeeper 2016-06-23 16:50:24 +02:00
parent 66df680e1b
commit 24946d3f13
2 changed files with 17 additions and 15 deletions

View file

@ -1,7 +1,7 @@
# Copyright (c) 2016 Ultimaker B.V. # Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
import UM.Settings.SettingsError #To indicate that a file is of incorrect format. import UM.VersionUpgrade #To indicate that a file is of incorrect format.
import configparser #To read config files. import configparser #To read config files.
import io #To write config files to strings as if they were files. import io #To write config files to strings as if they were files.
@ -15,7 +15,7 @@ import io #To write config files to strings as if they were files.
def importFrom(serialised): def importFrom(serialised):
try: try:
return MachineInstance(serialised) return MachineInstance(serialised)
except (configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError): except (configparser.Error, UM.VersionUpgrade.FormatException, UM.VersionUpgrade.InvalidVersionException):
return None return None
## A representation of a machine instance used as intermediary form for ## A representation of a machine instance used as intermediary form for
@ -30,15 +30,15 @@ class MachineInstance:
# Checking file correctness. # Checking file correctness.
if not config.has_section("general"): if not config.has_section("general"):
raise SettingsError.InvalidFormatError("general") raise UM.VersionUpgrade.FormatException("No \"general\" section.")
if not config.has_option("general", "version"): if not config.has_option("general", "version"):
raise SettingsError.InvalidFormatError("general/version") raise UM.VersionUpgrade.FormatException("No \"version\" in \"general\" section.")
if not config.has_option("general", "name"): if not config.has_option("general", "name"):
raise SettingsError.InvalidFormatError("general/name") raise UM.VersionUpgrade.FormatException("No \"name\" in \"general\" section.")
if not config.has_option("general", "type"): if not config.has_option("general", "type"):
raise SettingsError.InvalidFormatError("general/type") raise UM.VersionUpgrade.FormatException("No \"type\" in \"general\" section.")
if int(config.get("general", "version")) != 1: # Explicitly hard-code version 1, since if this number changes the programmer MUST change this entire function. if int(config.get("general", "version")) != 1: # Explicitly hard-code version 1, since if this number changes the programmer MUST change this entire function.
raise SettingsError.InvalidVersionError("Version upgrade intermediary version 1") raise UM.VersionUpgrade.InvalidVersionException("The version of this machine instance is wrong. It must be 1.")
self._type_name = config.get("general", "type") self._type_name = config.get("general", "type")
self._variant_name = config.get("general", "variant", fallback = None) self._variant_name = config.get("general", "variant", fallback = None)
@ -58,7 +58,6 @@ class MachineInstance:
# \return A serialised form of this machine instance, serialised in # \return A serialised form of this machine instance, serialised in
# version 2 of the file format. # version 2 of the file format.
def export(self): def export(self):
import VersionUpgrade21to22 # Import here to prevent circular dependencies.
config = configparser.ConfigParser(interpolation = None) # Build a config file in the form of version 2. config = configparser.ConfigParser(interpolation = None) # Build a config file in the form of version 2.
config.add_section("general") config.add_section("general")
@ -74,6 +73,7 @@ class MachineInstance:
if self._active_material_name: if self._active_material_name:
config.set("general", "material", self._active_material_name) config.set("general", "material", self._active_material_name)
import VersionUpgrade21to22 # Import here to prevent circular dependencies.
VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._machine_setting_overrides) VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._machine_setting_overrides)
config.add_section("machine_settings") config.add_section("machine_settings")
for key, value in self._machine_setting_overrides.items(): for key, value in self._machine_setting_overrides.items():

View file

@ -1,11 +1,11 @@
# Copyright (c) 2016 Ultimaker B.V. # Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
import UM.Settings.SettingsError #To indicate that a file is of incorrect format.
import configparser #To read config files. import configparser #To read config files.
import io #To write config files to strings as if they were files. import io #To write config files to strings as if they were files.
import UM.VersionUpgrade
## Creates a new profile instance by parsing a serialised profile in version 1 ## Creates a new profile instance by parsing a serialised profile in version 1
# of the file format. # of the file format.
# #
@ -14,7 +14,7 @@ import io #To write config files to strings as if they were files.
def importFrom(serialised): def importFrom(serialised):
try: try:
return Profile(serialised) return Profile(serialised)
except (configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError): except (configparser.Error, UM.VersionUpgrade.FormatException, UM.VersionUpgrade.InvalidVersionException):
return None return None
## A representation of a profile used as intermediary form for conversion from ## A representation of a profile used as intermediary form for conversion from
@ -29,9 +29,11 @@ class Profile:
# Check correctness. # Check correctness.
if not parser.has_section("general"): if not parser.has_section("general"):
raise SettingsError.InvalidFormatError("general") raise UM.VersionUpgrade.FormatException("No \"general\" section.")
if not parser.has_option("general", "version") or int(parser.get("general", "version")) != 1: # Hard-coded profile version here. If this number changes the entire function needs to change. if not parser.has_option("general", "version"):
raise SettingsError.InvalidVersionError("Version upgrade intermediary version 1") raise UM.VersionUpgrade.FormatException("No \"version\" in the \"general\" section.")
if int(parser.get("general", "version")) != 1: # Hard-coded profile version here. If this number changes the entire function needs to change.
raise UM.VersionUpgrade.InvalidVersionException("The version of this profile is wrong. It must be 1.")
# Parse the general section. # Parse the general section.
self._name = parser.get("general", "name") self._name = parser.get("general", "name")
@ -71,7 +73,6 @@ class Profile:
# \return A serialised form of this profile, serialised in version 2 of # \return A serialised form of this profile, serialised in version 2 of
# the file format. # the file format.
def export(self): def export(self):
import VersionUpgrade21to22 # Import here to prevent circular dependencies.
config = configparser.ConfigParser(interpolation = None) config = configparser.ConfigParser(interpolation = None)
config.add_section("general") config.add_section("general")
@ -90,6 +91,7 @@ class Profile:
if self._material_name and self._type != "material": if self._material_name and self._type != "material":
config.set("general", "material", self._material_name) config.set("general", "material", self._material_name)
import VersionUpgrade21to22 # Import here to prevent circular dependencies.
if self._settings: if self._settings:
VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings) VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings)
config.add_section("settings") config.add_section("settings")