mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-21 21:58:01 -06:00
CuraProfileWriter use SaveFile instead of streams
The SaveFile is safer since it should save the file atomically. This safety has proven important in the past so use it here too. Contributes to issue CURA-34.
This commit is contained in:
parent
3ec790f963
commit
a12246781d
1 changed files with 12 additions and 5 deletions
|
@ -2,18 +2,25 @@
|
||||||
# Copyright (c) 2013 David Braam
|
# Copyright (c) 2013 David Braam
|
||||||
# Uranium is released under the terms of the AGPLv3 or higher.
|
# Uranium is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
|
from UM.Logger import Logger
|
||||||
|
from UM.SaveFile import SaveFile
|
||||||
from UM.Settings.Profile import Profile
|
from UM.Settings.Profile import Profile
|
||||||
from UM.Settings.ProfileWriter import ProfileWriter
|
from UM.Settings.ProfileWriter import ProfileWriter
|
||||||
|
|
||||||
## Writes profiles to Cura's own profile format with config files.
|
## Writes profiles to Cura's own profile format with config files.
|
||||||
class CuraProfileWriter(ProfileWriter):
|
class CuraProfileWriter(ProfileWriter):
|
||||||
## Writes a profile to the specified stream.
|
## Writes a profile to the specified file path.
|
||||||
#
|
#
|
||||||
# \param stream \type{IOStream} The stream to write the profile to.
|
# \param path \type{string} The file to output to.
|
||||||
# \param profile \type{Profile} The profile to write to that stream.
|
# \param profile \type{Profile} The profile to write to that file.
|
||||||
# \return \code True \endcode if the writing was successful, or \code
|
# \return \code True \endcode if the writing was successful, or \code
|
||||||
# False \endcode if it wasn't.
|
# False \endcode if it wasn't.
|
||||||
def write(self, stream, profile):
|
def write(self, path, profile):
|
||||||
serialised = profile.serialise()
|
serialised = profile.serialise()
|
||||||
stream.write(serialised)
|
try:
|
||||||
|
with SaveFile(path, "wt", -1, "utf-8") as f: #Open the specified file.
|
||||||
|
f.write(serialised)
|
||||||
|
except Exception as e:
|
||||||
|
Logger.log("e", "Failed to write profile to %s: %s", path, str(e))
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue