diff options
author | Ghostkeeper <rubend@tutanota.com> | 2021-10-15 15:51:07 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2021-10-15 15:51:07 +0300 |
commit | dfcefe11cc4cd6e76c07ae96c65a053a00579064 (patch) | |
tree | e071348cb31818f53f6f863f1e9ca4707f39d27c /cura/PrinterOutput | |
parent | 2b4a31c9deba1fc59494f8372decad74bb57025b (diff) |
Use enum for printer status constants
This indicates how we're using it, and also allows for use of symbols in the code rather than strings, which integrate better with tooling.
Contributes to issue CURA-8609.
Diffstat (limited to 'cura/PrinterOutput')
-rw-r--r-- | cura/PrinterOutput/UploadMaterialsJob.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/cura/PrinterOutput/UploadMaterialsJob.py b/cura/PrinterOutput/UploadMaterialsJob.py index ff273c06c0..7d2a98ff11 100644 --- a/cura/PrinterOutput/UploadMaterialsJob.py +++ b/cura/PrinterOutput/UploadMaterialsJob.py @@ -45,6 +45,11 @@ class UploadMaterialsJob(Job): SUCCESS = 0 FAILED = 1 + class PrinterStatus(enum.Enum): + UPLOADING = "uploading" + SUCCESS = "success" + FAILED = "failed" + def __init__(self, material_sync: "CloudMaterialSync"): super().__init__() self._material_sync = material_sync @@ -68,7 +73,7 @@ class UploadMaterialsJob(Job): um_cloud_cluster_id = "*" # Required metadata field. Otherwise we get a KeyError. ) for printer in self._printer_metadata: - self._printer_sync_status[printer["host_guid"]] = "uploading" + self._printer_sync_status[printer["host_guid"]] = self.PrinterStatus.UPLOADING.value archive_file = tempfile.NamedTemporaryFile("wb", delete = False) archive_file.close() @@ -140,15 +145,15 @@ class UploadMaterialsJob(Job): def onUploadConfirmed(self, printer_id: str, reply: "QNetworkReply", error: Optional["QNetworkReply.NetworkError"]) -> None: if error is not None: Logger.error(f"Failed to confirm uploading material archive to printer {printer_id}: {error}") - self._printer_sync_status[printer_id] = "failed" + self._printer_sync_status[printer_id] = self.PrinterStatus.FAILED.value else: - self._printer_sync_status[printer_id] = "success" + self._printer_sync_status[printer_id] = self.PrinterStatus.SUCCESS.value - still_uploading = len([val for val in self._printer_sync_status.values() if val == "uploading"]) + still_uploading = len([val for val in self._printer_sync_status.values() if val == self.PrinterStatus.UPLOADING.value]) self.uploadProgressChanged.emit(0.8 + (len(self._printer_sync_status) - still_uploading) / len(self._printer_sync_status), self.getPrinterSyncStatus()) if still_uploading == 0: # This is the last response to be processed. - if "failed" in self._printer_sync_status.values(): + if self.PrinterStatus.FAILED.value in self._printer_sync_status.values(): self.setResult(self.Result.FAILED) self.setError(UploadMaterialsError(catalog.i18nc("@text:error", "Failed to connect to Digital Factory to sync materials with some of the printers."))) else: @@ -173,7 +178,7 @@ class UploadMaterialsJob(Job): self.setResult(self.Result.FAILED) self.setError(error) for printer_id in self._printer_sync_status: - self._printer_sync_status[printer_id] = "failed" + self._printer_sync_status[printer_id] = self.PrinterStatus.FAILED.value self.uploadProgressChanged.emit(1.0, self.getPrinterSyncStatus()) self.uploadCompleted.emit(self.getResult(), self.getError()) |