mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Exporting a profile now exports all profiles in a zipped container
CURA-2099
This commit is contained in:
parent
e7f2acfeab
commit
ced6cd7320
5 changed files with 42 additions and 22 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue