From 7bbd43928a4d8d3adcc7d8119995add058c57bea Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Fri, 11 Jan 2019 16:38:25 +0100 Subject: [PATCH] Fix more review comments --- plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py | 6 +++--- plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py | 2 ++ .../src/Cloud/CloudOutputDeviceManager.py | 3 +-- .../src/Cloud/{MeshUploader.py => ToolPathUploader.py} | 2 +- .../tests/Cloud/TestCloudOutputDeviceManager.py | 1 - 5 files changed, 7 insertions(+), 7 deletions(-) rename plugins/UM3NetworkPrinting/src/Cloud/{MeshUploader.py => ToolPathUploader.py} (99%) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py index f82d244fa9..9d6c29c0a4 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py @@ -11,7 +11,7 @@ from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply, QNetworkAccessManage from UM.Logger import Logger from cura import UltimakerCloudAuthentication from cura.API import Account -from .MeshUploader import MeshUploader +from .ToolPathUploader import ToolPathUploader from ..Models import BaseModel from .Models.CloudClusterResponse import CloudClusterResponse from .Models.CloudError import CloudError @@ -42,7 +42,7 @@ class CloudApiClient: self._manager = QNetworkAccessManager() self._account = account self._on_error = on_error - self._upload = None # type: Optional[MeshUploader] + self._upload = None # type: Optional[ToolPathUploader] # In order to avoid garbage collection we keep the callbacks in this list. self._anti_gc_callbacks = [] # type: List[Callable[[], None]] @@ -84,7 +84,7 @@ class CloudApiClient: # \param on_error: A function to be called if the upload fails. def uploadToolPath(self, print_job: CloudPrintJobResponse, mesh: bytes, on_finished: Callable[[], Any], on_progress: Callable[[int], Any], on_error: Callable[[], Any]): - self._upload = MeshUploader(self._manager, print_job, mesh, on_finished, on_progress, on_error) + self._upload = ToolPathUploader(self._manager, print_job, mesh, on_finished, on_progress, on_error) self._upload.start() # Requests a cluster to print the given print job. diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index 2cf6a3c236..2947cd421c 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -100,6 +100,8 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice): ## Connects this device. def connect(self) -> None: + if self.isConnected(): + return super().connect() Logger.log("i", "Connected to cluster %s", self.key) CuraApplication.getInstance().getBackend().backendStateChange.connect(self._onBackendStateChange) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index ba852e36c0..f9bd635bbd 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -131,8 +131,7 @@ class CloudOutputDeviceManager: ## Connects to an output device and makes sure it is registered in the output device manager. def _connectToOutputDevice(self, device: CloudOutputDevice) -> None: - if not device.isConnected(): - device.connect() + device.connect() self._output_device_manager.addOutputDevice(device) ## Handles an API error received from the cloud. diff --git a/plugins/UM3NetworkPrinting/src/Cloud/MeshUploader.py b/plugins/UM3NetworkPrinting/src/Cloud/ToolPathUploader.py similarity index 99% rename from plugins/UM3NetworkPrinting/src/Cloud/MeshUploader.py rename to plugins/UM3NetworkPrinting/src/Cloud/ToolPathUploader.py index cb721b872e..176b7e6ab7 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/MeshUploader.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/ToolPathUploader.py @@ -10,7 +10,7 @@ from .Models.CloudPrintJobResponse import CloudPrintJobResponse ## Class responsible for uploading meshes to the cloud in separate requests. -class MeshUploader: +class ToolPathUploader: # The maximum amount of times to retry if the server returns one of the RETRY_HTTP_CODES MAX_RETRIES = 10 diff --git a/plugins/UM3NetworkPrinting/tests/Cloud/TestCloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/tests/Cloud/TestCloudOutputDeviceManager.py index 96137a3edb..8b72c9d62d 100644 --- a/plugins/UM3NetworkPrinting/tests/Cloud/TestCloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/tests/Cloud/TestCloudOutputDeviceManager.py @@ -125,5 +125,4 @@ class TestCloudOutputDeviceManager(TestCase): } self.network.prepareReply("GET", self.URL, 200, self.clusters_response) self._loadData() - message_mock.assert_called_once_with(text='Not found!', title='Error', lifetime=10, dismissable=True) message_mock.return_value.show.assert_called_once_with()