mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
Remove exported file after fail
CURA-10180
This commit is contained in:
parent
fce35b78c4
commit
281e543255
1 changed files with 35 additions and 28 deletions
|
@ -1,6 +1,7 @@
|
||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
|
@ -143,38 +144,44 @@ class RemovableDriveOutputDevice(OutputDevice):
|
||||||
|
|
||||||
def _onFinished(self, job):
|
def _onFinished(self, job):
|
||||||
if self._stream:
|
if self._stream:
|
||||||
# Explicitly closing the stream flushes the write-buffer
|
error = job.getError()
|
||||||
try:
|
try:
|
||||||
|
# Explicitly closing the stream flushes the write-buffer
|
||||||
self._stream.close()
|
self._stream.close()
|
||||||
self._stream = None
|
except Exception as e:
|
||||||
except:
|
if not error:
|
||||||
Logger.logException("w", "An exception occurred while trying to write to removable drive.")
|
# Only log new error if there was no previous one
|
||||||
message = Message(catalog.i18nc("@info:status", "Could not save to removable drive {0}: {1}").format(self.getName(),str(job.getError())),
|
error = e
|
||||||
title = catalog.i18nc("@info:title", "Error"),
|
|
||||||
message_type = Message.MessageType.ERROR)
|
self._stream = None
|
||||||
|
self._writing = False
|
||||||
|
self.writeFinished.emit(self)
|
||||||
|
|
||||||
|
if not error:
|
||||||
|
message = Message(
|
||||||
|
catalog.i18nc("@info:status", "Saved to Removable Drive {0} as {1}").format(self.getName(),
|
||||||
|
os.path.basename(
|
||||||
|
job.getFileName())),
|
||||||
|
title=catalog.i18nc("@info:title", "File Saved"),
|
||||||
|
message_type=Message.MessageType.POSITIVE)
|
||||||
|
message.addAction("eject", catalog.i18nc("@action:button", "Eject"), "eject",
|
||||||
|
catalog.i18nc("@action", "Eject removable device {0}").format(self.getName()))
|
||||||
|
message.actionTriggered.connect(self._onActionTriggered)
|
||||||
|
message.show()
|
||||||
|
self.writeSuccess.emit(self)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
os.remove(job.getFileName())
|
||||||
|
except Exception as e:
|
||||||
|
Logger.logException("e", "Exception when trying to remove incomplete exported file %s",
|
||||||
|
str(job.getFileName()))
|
||||||
|
message = Message(catalog.i18nc("@info:status",
|
||||||
|
"Could not save to removable drive {0}: {1}").format(self.getName(),
|
||||||
|
str(job.getError())),
|
||||||
|
title=catalog.i18nc("@info:title", "Error"),
|
||||||
|
message_type=Message.MessageType.ERROR)
|
||||||
message.show()
|
message.show()
|
||||||
self.writeError.emit(self)
|
self.writeError.emit(self)
|
||||||
return
|
|
||||||
|
|
||||||
self._writing = False
|
|
||||||
self.writeFinished.emit(self)
|
|
||||||
if job.getResult():
|
|
||||||
message = Message(catalog.i18nc("@info:status", "Saved to Removable Drive {0} as {1}").format(self.getName(), os.path.basename(job.getFileName())),
|
|
||||||
title = catalog.i18nc("@info:title", "File Saved"),
|
|
||||||
message_type = Message.MessageType.POSITIVE)
|
|
||||||
message.addAction("eject", catalog.i18nc("@action:button", "Eject"), "eject", catalog.i18nc("@action", "Eject removable device {0}").format(self.getName()))
|
|
||||||
message.actionTriggered.connect(self._onActionTriggered)
|
|
||||||
message.show()
|
|
||||||
self.writeSuccess.emit(self)
|
|
||||||
else:
|
|
||||||
message = Message(catalog.i18nc("@info:status",
|
|
||||||
"Could not save to removable drive {0}: {1}").format(self.getName(),
|
|
||||||
str(job.getError())),
|
|
||||||
title = catalog.i18nc("@info:title", "Error"),
|
|
||||||
message_type = Message.MessageType.ERROR)
|
|
||||||
message.show()
|
|
||||||
self.writeError.emit(self)
|
|
||||||
job.getStream().close()
|
|
||||||
|
|
||||||
def _onActionTriggered(self, message, action):
|
def _onActionTriggered(self, message, action):
|
||||||
if action == "eject":
|
if action == "eject":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue