From f75b4739f68837476e7e6725ca783589a23002d7 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 8 Sep 2016 16:57:11 +0200 Subject: [PATCH 1/4] Added logging when the post was aborted due to connection loss CURA-2295 --- NetworkPrinterOutputDevice.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index 208ad80d51..7038c4e672 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -268,11 +268,13 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): # Some operating systems handle this themselves, others give weird issues. try: if self._post_reply: - self._post_reply.abort() + Logger.log("d", "Stopping post upload because the connection was lost.") try: self._post_reply.uploadProgress.disconnect(self._onUploadProgress) except TypeError: pass # The disconnection can fail on mac in some cases. Ignore that. + + self._post_reply.abort() self._progress_message.hide() except RuntimeError: self._post_reply = None # It can happen that the wrapped c++ object is already deleted. @@ -292,11 +294,13 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): # Some operating systems handle this themselves, others give weird issues. try: if self._post_reply: - self._post_reply.abort() + Logger.log("d", "Stopping post upload because the connection was lost.") try: self._post_reply.uploadProgress.disconnect(self._onUploadProgress) except TypeError: pass # The disconnection can fail on mac in some cases. Ignore that. + + self._post_reply.abort() self._progress_message.hide() except RuntimeError: self._post_reply = None # It can happen that the wrapped c++ object is already deleted. From f5886e5ecc64eee4ff4b7d2827b2b1595f64a2ea Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 8 Sep 2016 17:27:18 +0200 Subject: [PATCH 2/4] Counter is now only reset if no previous state was set --- NetworkPrinterOutputDevice.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index 7038c4e672..5e16c0d5f7 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -280,7 +280,8 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._post_reply = None # It can happen that the wrapped c++ object is already deleted. return else: - self._recreate_network_manager_count = 1 + if not self._connection_state_before_timeout: + self._recreate_network_manager_count = 1 # Check that we aren't in a timeout state if self._last_response_time and not self._connection_state_before_timeout: From a6a47b0aa27c331b38134498955e83c1e5e88f06 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 9 Sep 2016 10:25:12 +0200 Subject: [PATCH 3/4] Uploading g-codes is now done g-zipped CURA-2286 --- NetworkPrinterOutputDevice.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index 5e16c0d5f7..f65ef30f9b 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -17,6 +17,7 @@ from PyQt5.QtWidgets import QMessageBox import json import os +import gzip from time import time @@ -40,7 +41,9 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._properties = properties # Properties dict as provided by zero conf self._gcode = None - self._print_finished = True # _print_finsihed == False means we're halfway in a print + self._print_finished = True # _print_finsihed == False means we're halfway in a print + + self._use_gzip = True # Should we use g-zip compression before sending the data? # This holds the full JSON file that was received from the last request. # The JSON looks like: @@ -546,7 +549,12 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): for line in self._gcode: single_string_file_data += line - file_name = "%s.gcode" % Application.getInstance().getPrintInformation().jobName + if self._use_gzip: + file_name = "%s.gcode.gz" % Application.getInstance().getPrintInformation().jobName + single_string_file_data = gzip.compress(single_string_file_data.encode("utf-8")) + else: + file_name = "%s.gcode" % Application.getInstance().getPrintInformation().jobName + single_string_file_data = single_string_file_data.encode("utf-8") ## Create multi_part request self._post_multi_part = QHttpMultiPart(QHttpMultiPart.FormDataType) @@ -555,7 +563,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._post_part = QHttpPart() self._post_part.setHeader(QNetworkRequest.ContentDispositionHeader, "form-data; name=\"file\"; filename=\"%s\"" % file_name) - self._post_part.setBody(single_string_file_data.encode()) + self._post_part.setBody(single_string_file_data) self._post_multi_part.append(self._post_part) url = QUrl("http://" + self._address + self._api_prefix + "print_job") From 97cf79c2e18ce001da1a94a3620b493104e44ab0 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 9 Sep 2016 11:04:16 +0200 Subject: [PATCH 4/4] If serialization of XML fails, we don't try to send it to the printer --- NetworkPrinterOutputDevice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index f65ef30f9b..4fef337b13 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -607,7 +607,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "material"): try: xml_data = container.serialize() - if xml_data == "": + if xml_data == "" or xml_data is None: continue material_multi_part = QHttpMultiPart(QHttpMultiPart.FormDataType)