mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 23:46:22 -06:00
Handle bunch of review comments
CURA-6005
This commit is contained in:
parent
4d1e9d24f9
commit
ed9a51791b
2 changed files with 13 additions and 12 deletions
|
@ -17,6 +17,9 @@ from cura.CuraApplication import CuraApplication
|
||||||
from .UploadBackupJob import UploadBackupJob
|
from .UploadBackupJob import UploadBackupJob
|
||||||
from .Settings import Settings
|
from .Settings import Settings
|
||||||
|
|
||||||
|
from UM.i18n import i18nCatalog
|
||||||
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
## The DriveApiService is responsible for interacting with the CuraDrive API and Cura's backup handling.
|
## The DriveApiService is responsible for interacting with the CuraDrive API and Cura's backup handling.
|
||||||
class DriveApiService:
|
class DriveApiService:
|
||||||
|
@ -43,10 +46,9 @@ class DriveApiService:
|
||||||
"Authorization": "Bearer {}".format(access_token)
|
"Authorization": "Bearer {}".format(access_token)
|
||||||
})
|
})
|
||||||
|
|
||||||
if backup_list_request.status_code > 299:
|
if backup_list_request.status_code >= 300:
|
||||||
Logger.log("w", "Could not get backups list from remote: %s", backup_list_request.text)
|
Logger.log("w", "Could not get backups list from remote: %s", backup_list_request.text)
|
||||||
Message(Settings.translatable_messages["get_backups_error"], title = Settings.MESSAGE_TITLE,
|
Message(catalog.i18nc("@info:backup_status", "There was an error listing your backups."), title = Settings.MESSAGE_TITLE).show()
|
||||||
lifetime = 10).show()
|
|
||||||
return []
|
return []
|
||||||
return backup_list_request.json()["data"]
|
return backup_list_request.json()["data"]
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@ class DriveApiService:
|
||||||
return self._emitRestoreError()
|
return self._emitRestoreError()
|
||||||
|
|
||||||
download_package = requests.get(download_url, stream = True)
|
download_package = requests.get(download_url, stream = True)
|
||||||
if download_package.status_code != 200:
|
if download_package.status_code >= 300:
|
||||||
# Something went wrong when attempting to download the backup.
|
# Something went wrong when attempting to download the backup.
|
||||||
Logger.log("w", "Could not download backup from url %s: %s", download_url, download_package.text)
|
Logger.log("w", "Could not download backup from url %s: %s", download_url, download_package.text)
|
||||||
return self._emitRestoreError()
|
return self._emitRestoreError()
|
||||||
|
@ -109,11 +111,10 @@ class DriveApiService:
|
||||||
self._cura_api.backups.restoreBackup(read_backup.read(), backup.get("data"))
|
self._cura_api.backups.restoreBackup(read_backup.read(), backup.get("data"))
|
||||||
self.onRestoringStateChanged.emit(is_restoring = False)
|
self.onRestoringStateChanged.emit(is_restoring = False)
|
||||||
|
|
||||||
def _emitRestoreError(self, error_message: str = Settings.translatable_messages["backup_restore_error_message"]):
|
def _emitRestoreError(self):
|
||||||
self.onRestoringStateChanged.emit(
|
self.onRestoringStateChanged.emit(is_restoring = False,
|
||||||
is_restoring = False,
|
error_message = catalog.i18nc("@info:backup_status",
|
||||||
error_message = error_message
|
"There was an error trying to restore your backup."))
|
||||||
)
|
|
||||||
|
|
||||||
# Verify the MD5 hash of a file.
|
# Verify the MD5 hash of a file.
|
||||||
# \param file_path Full path to the file.
|
# \param file_path Full path to the file.
|
||||||
|
@ -134,7 +135,7 @@ class DriveApiService:
|
||||||
delete_backup = requests.delete("{}/{}".format(self.DELETE_BACKUP_URL, backup_id), headers = {
|
delete_backup = requests.delete("{}/{}".format(self.DELETE_BACKUP_URL, backup_id), headers = {
|
||||||
"Authorization": "Bearer {}".format(access_token)
|
"Authorization": "Bearer {}".format(access_token)
|
||||||
})
|
})
|
||||||
if delete_backup.status_code > 299:
|
if delete_backup.status_code >= 300:
|
||||||
Logger.log("w", "Could not delete backup: %s", delete_backup.text)
|
Logger.log("w", "Could not delete backup: %s", delete_backup.text)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Settings:
|
||||||
I18N_CATALOG_ID = "cura"
|
I18N_CATALOG_ID = "cura"
|
||||||
I18N_CATALOG = i18nCatalog(I18N_CATALOG_ID)
|
I18N_CATALOG = i18nCatalog(I18N_CATALOG_ID)
|
||||||
|
|
||||||
MESSAGE_TITLE = I18N_CATALOG.i18nc("@info:title", "Backups"),
|
MESSAGE_TITLE = I18N_CATALOG.i18nc("@info:title", "Backups")
|
||||||
|
|
||||||
# Translatable messages for the entire plugin.
|
# Translatable messages for the entire plugin.
|
||||||
translatable_messages = {
|
translatable_messages = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue