CuraProfileWriter.py 1018 B

1234567891011121314151617181920212223242526
  1. # Copyright (c) 2015 Ultimaker B.V.
  2. # Copyright (c) 2013 David Braam
  3. # Uranium is released under the terms of the AGPLv3 or higher.
  4. from UM.Logger import Logger
  5. from UM.SaveFile import SaveFile
  6. from cura.ProfileWriter import ProfileWriter
  7. ## Writes profiles to Cura's own profile format with config files.
  8. class CuraProfileWriter(ProfileWriter):
  9. ## Writes a profile to the specified file path.
  10. #
  11. # \param path \type{string} The file to output to.
  12. # \param profile \type{Profile} The profile to write to that file.
  13. # \return \code True \endcode if the writing was successful, or \code
  14. # False \endcode if it wasn't.
  15. def write(self, path, profile):
  16. serialized = profile.serialize()
  17. try:
  18. with SaveFile(path, "wt", -1, "utf-8") as f: # Open the specified file.
  19. f.write(serialized)
  20. except Exception as e:
  21. Logger.log("e", "Failed to write profile to %s: %s", path, str(e))
  22. return False
  23. return True