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()
|
||||
|
||||
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.
|
||||
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:
|
||||
self.creatingStateChanged.emit(is_creating = False)
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# 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.Logger import Logger
|
||||
from UM.Message import Message
|
||||
from UM.TaskManagement.HttpRequestManager import HttpRequestManager
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog("cura")
|
||||
|
@ -21,32 +21,19 @@ class UploadBackupJob(Job):
|
|||
self._signed_upload_url = signed_upload_url
|
||||
self._backup_zip = backup_zip
|
||||
self._upload_success = False
|
||||
self.backup_upload_error_text = ""
|
||||
self._message = None
|
||||
self.backup_upload_error_message = ""
|
||||
|
||||
def run(self) -> None:
|
||||
self._message = Message(catalog.i18nc("@info:backup_status", "Uploading your backup..."), title = self.MESSAGE_TITLE, progress = -1)
|
||||
self._message.show()
|
||||
upload_message = Message(catalog.i18nc("@info:backup_status", "Uploading your backup..."), title = self.MESSAGE_TITLE, progress = -1)
|
||||
upload_message.show()
|
||||
|
||||
HttpRequestManager.getInstance().put(
|
||||
self._signed_upload_url,
|
||||
data = self._backup_zip,
|
||||
callback = self.uploadFinishedCallback,
|
||||
error_callback = self.uploadFinishedCallback
|
||||
)
|
||||
backup_upload = requests.put(self._signed_upload_url, data = self._backup_zip)
|
||||
upload_message.hide()
|
||||
|
||||
def uploadFinishedCallback(self, reply: QNetworkReply, error: QNetworkReply.NetworkError = None):
|
||||
self._message.hide()
|
||||
|
||||
self.backup_upload_error_text = HttpRequestManager.readText(reply)
|
||||
|
||||
if HttpRequestManager.replyIndicatesSuccess(reply, error):
|
||||
if backup_upload.status_code >= 300:
|
||||
self.backup_upload_error_message = backup_upload.text
|
||||
Logger.log("w", "Could not upload backup file: %s", backup_upload.text)
|
||||
Message(catalog.i18nc("@info:backup_status", "There was an error while uploading your backup."), title = self.MESSAGE_TITLE).show()
|
||||
else:
|
||||
self._upload_success = True
|
||||
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