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 13:55:31 +0300
committerJaime van Kessel <nallath@gmail.com>2016-08-26 13:55:31 +0300
commitced6cd732052cb679c2c84fff06ba1e8bdeab8f5 (patch)
treeecc616fce4c72062195363fed935aa999527ea8b /plugins/CuraProfileWriter
parente7f2acfeab9e2341730a0d15ed8d92b246fe9e79 (diff)
Exporting a profile now exports all profiles in a zipped container
CURA-2099
Diffstat (limited to 'plugins/CuraProfileWriter')
-rw-r--r--plugins/CuraProfileWriter/CuraProfileWriter.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/plugins/CuraProfileWriter/CuraProfileWriter.py b/plugins/CuraProfileWriter/CuraProfileWriter.py
index 86b4f7dc89..cd3681b86f 100644
--- a/plugins/CuraProfileWriter/CuraProfileWriter.py
+++ b/plugins/CuraProfileWriter/CuraProfileWriter.py
@@ -5,22 +5,31 @@
from UM.Logger import Logger
from UM.SaveFile import SaveFile
from cura.ProfileWriter import ProfileWriter
-
+import zipfile
## Writes profiles to Cura's own profile format with config files.
class CuraProfileWriter(ProfileWriter):
## Writes a profile to the specified file path.
#
# \param path \type{string} The file to output to.
- # \param profile \type{Profile} The profile to write to that file.
+ # \param profiles \type{Profile} \type{List} The profile(s) to write to that file.
# \return \code True \endcode if the writing was successful, or \code
# False \endcode if it wasn't.
- def write(self, path, profile):
- serialized = profile.serialize()
+ def write(self, path, profiles):
+ if type(profiles) != list:
+ profiles = [profiles]
+
+ stream = open(path, "wb") # Open file for writing in binary.
+ archive = zipfile.ZipFile(stream, "w", compression=zipfile.ZIP_DEFLATED)
try:
- with SaveFile(path, "wt", -1, "utf-8") as f: # Open the specified file.
- f.write(serialized)
+ # Open the specified file.
+ for profile in profiles:
+ serialized = profile.serialize()
+ profile_file = zipfile.ZipInfo(profile.getId())
+ archive.writestr(profile_file, serialized)
except Exception as e:
Logger.log("e", "Failed to write profile to %s: %s", path, str(e))
return False
+ finally:
+ archive.close()
return True