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

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime van Kessel <nallath@gmail.com>2016-08-26 15:37:21 +0300
committerJaime van Kessel <nallath@gmail.com>2016-08-26 15:37:21 +0300
commitfcfbf78f9e3a2986b2c83236382e48b14d7656ce (patch)
treed98b26c983d27fb58dce3fe89db2d9dca663d41f /plugins/CuraProfileReader
parentced6cd732052cb679c2c84fff06ba1e8bdeab8f5 (diff)
Implemented importing multiple profiles from .curaprofile file
CURA-2099
Diffstat (limited to 'plugins/CuraProfileReader')
-rw-r--r--plugins/CuraProfileReader/CuraProfileReader.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/plugins/CuraProfileReader/CuraProfileReader.py b/plugins/CuraProfileReader/CuraProfileReader.py
index 261e68a26b..8007a8e696 100644
--- a/plugins/CuraProfileReader/CuraProfileReader.py
+++ b/plugins/CuraProfileReader/CuraProfileReader.py
@@ -4,9 +4,11 @@
import os.path
from UM.Logger import Logger
-from UM.Settings.InstanceContainer import InstanceContainer #The new profile to make.
+from UM.Settings.InstanceContainer import InstanceContainer # The new profile to make.
from cura.ProfileReader import ProfileReader
+import zipfile
+
## A plugin that reads profile data from Cura profile files.
#
# It reads a profile from a .curaprofile file, and returns it as a profile
@@ -24,19 +26,19 @@ class CuraProfileReader(ProfileReader):
# not be read or didn't contain a valid profile, \code None \endcode is
# returned.
def read(self, file_name):
- # Create an empty profile.
- profile = InstanceContainer(os.path.basename(os.path.splitext(file_name)[0]))
- profile.addMetaDataEntry("type", "quality")
- try:
- with open(file_name) as f: # Open file for reading.
+ archive = zipfile.ZipFile(file_name, "r")
+ results = []
+ for profile_id in archive.namelist():
+ # Create an empty profile.
+ profile = InstanceContainer(profile_id)
+ profile.addMetaDataEntry("type", "quality_changes")
+ serialized = ""
+ with archive.open(profile_id) as f:
serialized = f.read()
- except IOError as e:
- Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e))
- return None
-
- try:
- profile.deserialize(serialized)
- except Exception as e: # Parsing error. This is not a (valid) Cura profile then.
- Logger.log("e", "Error while trying to parse profile: %s", str(e))
- return None
- return profile \ No newline at end of file
+ try:
+ profile.deserialize(serialized.decode("utf-8") )
+ except Exception as e: # Parsing error. This is not a (valid) Cura profile then.
+ Logger.log("e", "Error while trying to parse profile: %s", str(e))
+ continue
+ results.append(profile)
+ return results \ No newline at end of file