diff options
author | Ghostkeeper <rubend@tutanota.com> | 2020-03-25 11:12:00 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2020-03-25 11:12:14 +0300 |
commit | 2b003c30dce2e623bc7226fef3fa20c618b328ba (patch) | |
tree | f096f4099cf7593373fe44f8b6a5589114e0fd7a /plugins/3MFWriter | |
parent | 7ab005e423703a6f4409af8fafb551ba8ac3dc73 (diff) |
Catch PermissionError when writing workspaces
We'll want to give a proper error message then. We have no mechanism right now to show a message on the screen particular to this error. Instead we'll let it fail (the user sees a message that writing fails) and put a message in the log why it failed.
Fixes Sentry error CURA-DK.
Diffstat (limited to 'plugins/3MFWriter')
-rw-r--r-- | plugins/3MFWriter/ThreeMFWorkspaceWriter.py | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/plugins/3MFWriter/ThreeMFWorkspaceWriter.py b/plugins/3MFWriter/ThreeMFWorkspaceWriter.py index 10a21f445b..6c7a82a588 100644 --- a/plugins/3MFWriter/ThreeMFWorkspaceWriter.py +++ b/plugins/3MFWriter/ThreeMFWorkspaceWriter.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Ultimaker B.V. +# Copyright (c) 2020 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. import configparser @@ -6,6 +6,7 @@ from io import StringIO import zipfile from UM.Application import Application +from UM.Logger import Logger from UM.Preferences import Preferences from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Workspace.WorkspaceWriter import WorkspaceWriter @@ -25,6 +26,7 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter): mesh_writer = application.getMeshFileHandler().getWriter("3MFWriter") if not mesh_writer: # We need to have the 3mf mesh writer, otherwise we can't save the entire workspace + Logger.error("3MF Writer class is unavailable. Can't write workspace.") return False # Indicate that the 3mf mesh writer should not close the archive just yet (we still need to add stuff to it). @@ -59,24 +61,28 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter): preferences_string = StringIO() temp_preferences.writeToFile(preferences_string) preferences_file = zipfile.ZipInfo("Cura/preferences.cfg") - archive.writestr(preferences_file, preferences_string.getvalue()) - - # Save Cura version - version_file = zipfile.ZipInfo("Cura/version.ini") - version_config_parser = configparser.ConfigParser(interpolation = None) - version_config_parser.add_section("versions") - version_config_parser.set("versions", "cura_version", application.getVersion()) - version_config_parser.set("versions", "build_type", application.getBuildType()) - version_config_parser.set("versions", "is_debug_mode", str(application.getIsDebugMode())) - - version_file_string = StringIO() - version_config_parser.write(version_file_string) - archive.writestr(version_file, version_file_string.getvalue()) - - self._writePluginMetadataToArchive(archive) - - # Close the archive & reset states. - archive.close() + try: + archive.writestr(preferences_file, preferences_string.getvalue()) + + # Save Cura version + version_file = zipfile.ZipInfo("Cura/version.ini") + version_config_parser = configparser.ConfigParser(interpolation = None) + version_config_parser.add_section("versions") + version_config_parser.set("versions", "cura_version", application.getVersion()) + version_config_parser.set("versions", "build_type", application.getBuildType()) + version_config_parser.set("versions", "is_debug_mode", str(application.getIsDebugMode())) + + version_file_string = StringIO() + version_config_parser.write(version_file_string) + archive.writestr(version_file, version_file_string.getvalue()) + + self._writePluginMetadataToArchive(archive) + + # Close the archive & reset states. + archive.close() + except PermissionError: + Logger.error("No permission to write workspace to this stream.") + return False mesh_writer.setStoreArchive(False) return True |