CuraProfileWriter.py 1.0 KB

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 UM.Settings.Profile import Profile
  7. from UM.Settings.ProfileWriter import ProfileWriter
  8. ## Writes profiles to Cura's own profile format with config files.
  9. class CuraProfileWriter(ProfileWriter):
  10. ## Writes a profile to the specified file path.
  11. #
  12. # \param path \type{string} The file to output to.
  13. # \param profile \type{Profile} The profile to write to that file.
  14. # \return \code True \endcode if the writing was successful, or \code
  15. # False \endcode if it wasn't.
  16. def write(self, path, profile):
  17. serialised = profile.serialise()
  18. try:
  19. with SaveFile(path, "wt", -1, "utf-8") as f: #Open the specified file.
  20. f.write(serialised)
  21. except Exception as e:
  22. Logger.log("e", "Failed to write profile to %s: %s", path, str(e))
  23. return False
  24. return True