Use toolpath instead of mesh, some review fixes

This commit is contained in:
ChrisTerBeke 2019-01-11 16:18:47 +01:00
parent d8b5f75e2a
commit e465bd771a
4 changed files with 8 additions and 8 deletions

View file

@ -275,7 +275,7 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
def postFormWithParts(self, target: str, parts: List[QHttpPart], def postFormWithParts(self, target: str, parts: List[QHttpPart],
on_finished: Optional[Callable[[QNetworkReply], None]], on_finished: Optional[Callable[[QNetworkReply], None]],
on_progress: Callable = None) -> QNetworkReply: on_progress: Optional[Callable[[int, int], None]] = None) -> QNetworkReply:
self._validateManager() self._validateManager()
request = self._createEmptyRequest(target, content_type=None) request = self._createEmptyRequest(target, content_type=None)
multi_post_part = QHttpMultiPart(QHttpMultiPart.FormDataType) multi_post_part = QHttpMultiPart(QHttpMultiPart.FormDataType)

View file

@ -76,13 +76,13 @@ class CloudApiClient:
reply = self._manager.put(self._createEmptyRequest(url), body.encode()) reply = self._manager.put(self._createEmptyRequest(url), body.encode())
self._addCallback(reply, on_finished, CloudPrintJobResponse) self._addCallback(reply, on_finished, CloudPrintJobResponse)
## Uploads a print job mesh to the cloud. ## Uploads a print job tool path to the cloud.
# \param print_job: The object received after requesting an upload with `self.requestUpload`. # \param print_job: The object received after requesting an upload with `self.requestUpload`.
# \param mesh: The mesh data to be uploaded. # \param mesh: The tool path data to be uploaded.
# \param on_finished: The function to be called after the upload is successful. # \param on_finished: The function to be called after the upload is successful.
# \param on_progress: A function to be called during upload progress. It receives a percentage (0-100). # \param on_progress: A function to be called during upload progress. It receives a percentage (0-100).
# \param on_error: A function to be called if the upload fails. # \param on_error: A function to be called if the upload fails.
def uploadMesh(self, print_job: CloudPrintJobResponse, mesh: bytes, on_finished: Callable[[], Any], def uploadToolPath(self, print_job: CloudPrintJobResponse, mesh: bytes, on_finished: Callable[[], Any],
on_progress: Callable[[int], Any], on_error: 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 = MeshUploader(self._manager, print_job, mesh, on_finished, on_progress, on_error)
self._upload.start() self._upload.start()

View file

@ -302,7 +302,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
self._progress.show() self._progress.show()
self._uploaded_print_job = job_response self._uploaded_print_job = job_response
mesh = cast(bytes, self._mesh) mesh = cast(bytes, self._mesh)
self._api.uploadMesh(job_response, mesh, self._onPrintJobUploaded, self._progress.update, self._onUploadError) self._api.uploadToolPath(job_response, mesh, self._onPrintJobUploaded, self._progress.update, self._onUploadError)
## Requests the print to be sent to the printer when we finished uploading the mesh. ## Requests the print to be sent to the printer when we finished uploading the mesh.
def _onPrintJobUploaded(self) -> None: def _onPrintJobUploaded(self) -> None:

View file

@ -74,7 +74,7 @@ class TestCloudApiClient(TestCase):
self.assertEqual(["text/plain"], [r.content_type for r in results]) self.assertEqual(["text/plain"], [r.content_type for r in results])
self.assertEqual(["uploading"], [r.status for r in results]) self.assertEqual(["uploading"], [r.status for r in results])
def test_uploadMesh(self): def test_uploadToolPath(self):
results = [] results = []
progress = MagicMock() progress = MagicMock()
@ -86,7 +86,7 @@ class TestCloudApiClient(TestCase):
self.network.prepareReply("PUT", upload_response.upload_url, 200, b'{}') self.network.prepareReply("PUT", upload_response.upload_url, 200, b'{}')
mesh = ("1234" * 100000).encode() mesh = ("1234" * 100000).encode()
self.api.uploadMesh(upload_response, mesh, lambda: results.append("sent"), progress.advance, progress.error) self.api.uploadToolPath(upload_response, mesh, lambda: results.append("sent"), progress.advance, progress.error)
for _ in range(10): for _ in range(10):
self.network.flushReplies() self.network.flushReplies()