mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Profile importing now checks if it's the right file type
Contributes to CURA-936
This commit is contained in:
parent
a72180ebf2
commit
e90fd95495
2 changed files with 7 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
from UM.Application import Application #To get the machine manager to create the new profile in.
|
from UM.Application import Application #To get the machine manager to create the new profile in.
|
||||||
from UM.Settings.Profile import Profile
|
from UM.Settings.Profile import Profile
|
||||||
from UM.Settings.ProfileReader import ProfileReader
|
from UM.Settings.ProfileReader import ProfileReader
|
||||||
|
from UM.Logger import Logger
|
||||||
import re #Regular expressions for parsing escape characters in the settings.
|
import re #Regular expressions for parsing escape characters in the settings.
|
||||||
|
|
||||||
## A class that reads profile data from g-code files.
|
## A class that reads profile data from g-code files.
|
||||||
|
@ -40,6 +41,9 @@ class GCodeProfileReader(ProfileReader):
|
||||||
# specified file was no g-code or contained no parsable profile, \code
|
# specified file was no g-code or contained no parsable profile, \code
|
||||||
# None \endcode is returned.
|
# None \endcode is returned.
|
||||||
def read(self, file_name):
|
def read(self, file_name):
|
||||||
|
if file_name.split(".")[-1] != "gcode":
|
||||||
|
return None
|
||||||
|
|
||||||
prefix = ";SETTING_" + str(GCodeProfileReader.version) + " "
|
prefix = ";SETTING_" + str(GCodeProfileReader.version) + " "
|
||||||
prefix_length = len(prefix)
|
prefix_length = len(prefix)
|
||||||
|
|
||||||
|
@ -63,5 +67,6 @@ class GCodeProfileReader(ProfileReader):
|
||||||
try:
|
try:
|
||||||
profile.unserialise(serialised)
|
profile.unserialise(serialised)
|
||||||
except Exception as e: #Not a valid g-code file.
|
except Exception as e: #Not a valid g-code file.
|
||||||
|
Logger.log("e", "Unable to serialise the profile: %s", str(e))
|
||||||
return None
|
return None
|
||||||
return profile
|
return profile
|
|
@ -63,6 +63,8 @@ class LegacyProfileReader(ProfileReader):
|
||||||
# file could not be read or didn't contain a valid profile, \code None
|
# file could not be read or didn't contain a valid profile, \code None
|
||||||
# \endcode is returned.
|
# \endcode is returned.
|
||||||
def read(self, file_name):
|
def read(self, file_name):
|
||||||
|
if file_name.split(".")[-1] != "ini":
|
||||||
|
return None
|
||||||
Logger.log("i", "Importing legacy profile from file " + file_name + ".")
|
Logger.log("i", "Importing legacy profile from file " + file_name + ".")
|
||||||
profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False) #Create an empty profile.
|
profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False) #Create an empty profile.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue