From b3e3053323cbc30faa0dfbf02d55c30e8d04b74a Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 17 Oct 2016 13:22:41 +0200 Subject: [PATCH] Move automatic file name generating to separate function This will make it easier to have multiple nodes here in the future. I'll have to modify this function for that, but I'll do that in a separate commit. Contributes to issue CURA-2617. --- .../RemovableDriveOutputDevice.py | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py b/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py index 8b6dce8292..2cd33dafdc 100644 --- a/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py +++ b/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py @@ -50,15 +50,7 @@ class RemovableDriveOutputDevice(OutputDevice): extension = file_formats[0]["extension"] if file_name is None: - for n in BreadthFirstIterator(node): - if n.getMeshData(): - file_name = n.getName() - if file_name: - break - - if not file_name: - Logger.log("e", "Could not determine a proper file name when trying to write to %s, aborting", self.getName()) - raise OutputDeviceError.WriteRequestFailedError() + file_name = self._automaticFileName(node) if extension: # Not empty string. extension = "." + extension @@ -88,6 +80,21 @@ class RemovableDriveOutputDevice(OutputDevice): Logger.log("e", "Operating system would not let us write to %s: %s", file_name, str(e)) raise OutputDeviceError.WriteRequestFailedError(catalog.i18nc("@info:status", "Could not save to {0}: {1}").format(file_name, str(e))) from e + ## Generate a file name automatically for the specified nodes to be saved + # in. + # + # The name generated will be the name of one of the nodes. Which node that + # is can not be guaranteed. + # + # \param root A node for which to generate a file name. + def _automaticFileName(self, root): + for child in BreadthFirstIterator(root): + if child.getMeshData(): + name = child.getName() + if name: + return name + raise OutputDeviceError.WriteRequestFailedError("Could not find a file name when trying to write to {device}.".format(device = self.getName())) + def _onProgress(self, job, progress): if hasattr(job, "_message"): job._message.setProgress(progress)