mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-13 09:47:50 -06:00
Revert: Refactor UploadBackupJob to use HttpRequestManager
It doesn't make sense to have a Job using HttpRequestManager because both are async and Note that the job itself should not emit finished, the JobQueue does that.
This commit is contained in:
parent
6c9b9909ba
commit
7243dc63a4
2 changed files with 14 additions and 27 deletions
|
@ -87,9 +87,9 @@ class DriveApiService:
|
||||||
upload_backup_job.start()
|
upload_backup_job.start()
|
||||||
|
|
||||||
def _onUploadFinished(self, job: "UploadBackupJob") -> None:
|
def _onUploadFinished(self, job: "UploadBackupJob") -> None:
|
||||||
if job.backup_upload_error_text != "":
|
if job.backup_upload_error_message != "":
|
||||||
# If the job contains an error message we pass it along so the UI can display it.
|
# If the job contains an error message we pass it along so the UI can display it.
|
||||||
self.creatingStateChanged.emit(is_creating = False, error_message = job.backup_upload_error_text)
|
self.creatingStateChanged.emit(is_creating = False, error_message = job.backup_upload_error_message)
|
||||||
else:
|
else:
|
||||||
self.creatingStateChanged.emit(is_creating = False)
|
self.creatingStateChanged.emit(is_creating = False)
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# 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.
|
||||||
from PyQt5.QtNetwork import QNetworkReply
|
|
||||||
|
import requests
|
||||||
|
|
||||||
from UM.Job import Job
|
from UM.Job import Job
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Message import Message
|
from UM.Message import Message
|
||||||
from UM.TaskManagement.HttpRequestManager import HttpRequestManager
|
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
@ -21,32 +21,19 @@ class UploadBackupJob(Job):
|
||||||
self._signed_upload_url = signed_upload_url
|
self._signed_upload_url = signed_upload_url
|
||||||
self._backup_zip = backup_zip
|
self._backup_zip = backup_zip
|
||||||
self._upload_success = False
|
self._upload_success = False
|
||||||
self.backup_upload_error_text = ""
|
self.backup_upload_error_message = ""
|
||||||
self._message = None
|
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self._message = Message(catalog.i18nc("@info:backup_status", "Uploading your backup..."), title = self.MESSAGE_TITLE, progress = -1)
|
upload_message = Message(catalog.i18nc("@info:backup_status", "Uploading your backup..."), title = self.MESSAGE_TITLE, progress = -1)
|
||||||
self._message.show()
|
upload_message.show()
|
||||||
|
|
||||||
HttpRequestManager.getInstance().put(
|
backup_upload = requests.put(self._signed_upload_url, data = self._backup_zip)
|
||||||
self._signed_upload_url,
|
upload_message.hide()
|
||||||
data = self._backup_zip,
|
|
||||||
callback = self.uploadFinishedCallback,
|
|
||||||
error_callback = self.uploadFinishedCallback
|
|
||||||
)
|
|
||||||
|
|
||||||
def uploadFinishedCallback(self, reply: QNetworkReply, error: QNetworkReply.NetworkError = None):
|
if backup_upload.status_code >= 300:
|
||||||
self._message.hide()
|
self.backup_upload_error_message = backup_upload.text
|
||||||
|
Logger.log("w", "Could not upload backup file: %s", backup_upload.text)
|
||||||
self.backup_upload_error_text = HttpRequestManager.readText(reply)
|
Message(catalog.i18nc("@info:backup_status", "There was an error while uploading your backup."), title = self.MESSAGE_TITLE).show()
|
||||||
|
else:
|
||||||
if HttpRequestManager.replyIndicatesSuccess(reply, error):
|
|
||||||
self._upload_success = True
|
self._upload_success = True
|
||||||
Message(catalog.i18nc("@info:backup_status", "Your backup has finished uploading."), title = self.MESSAGE_TITLE).show()
|
Message(catalog.i18nc("@info:backup_status", "Your backup has finished uploading."), title = self.MESSAGE_TITLE).show()
|
||||||
else:
|
|
||||||
self.backup_upload_error_text = self.backup_upload_error_text
|
|
||||||
Logger.log("w", "Could not upload backup file: %s", self.backup_upload_error_text)
|
|
||||||
Message(catalog.i18nc("@info:backup_status", "There was an error while uploading your backup."),
|
|
||||||
title=self.MESSAGE_TITLE).show()
|
|
||||||
|
|
||||||
self.finished.emit(self)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue