mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-11 00:37:50 -06:00
Clean up CloudApiClient.py
This commit is contained in:
parent
8012df6518
commit
484cc6d42f
1 changed files with 25 additions and 21 deletions
|
@ -82,10 +82,10 @@ class CloudApiClient:
|
||||||
|
|
||||||
url = f"{self.CLUSTER_API_ROOT}/clusters?status=active"
|
url = f"{self.CLUSTER_API_ROOT}/clusters?status=active"
|
||||||
self._http.get(url,
|
self._http.get(url,
|
||||||
scope = self._scope,
|
scope=self._scope,
|
||||||
callback = self._parseCallback(on_finished, CloudClusterResponse, failed),
|
callback=self._parseCallback(on_finished, CloudClusterResponse, failed),
|
||||||
error_callback = failed,
|
error_callback=failed,
|
||||||
timeout = self.DEFAULT_REQUEST_TIMEOUT)
|
timeout=self.DEFAULT_REQUEST_TIMEOUT)
|
||||||
|
|
||||||
def getClustersByMachineType(self, machine_type, on_finished: Callable[[List[CloudClusterWithConfigResponse]], Any], failed: Callable) -> None:
|
def getClustersByMachineType(self, machine_type, on_finished: Callable[[List[CloudClusterWithConfigResponse]], Any], failed: Callable) -> None:
|
||||||
# HACK: There is something weird going on with the API, as it reports printer types in formats like
|
# HACK: There is something weird going on with the API, as it reports printer types in formats like
|
||||||
|
@ -118,9 +118,9 @@ class CloudApiClient:
|
||||||
|
|
||||||
url = f"{self.CLUSTER_API_ROOT}/clusters/{cluster_id}/status"
|
url = f"{self.CLUSTER_API_ROOT}/clusters/{cluster_id}/status"
|
||||||
self._http.get(url,
|
self._http.get(url,
|
||||||
scope = self._scope,
|
scope=self._scope,
|
||||||
callback = self._parseCallback(on_finished, CloudClusterStatus),
|
callback=self._parseCallback(on_finished, CloudClusterStatus),
|
||||||
timeout = self.DEFAULT_REQUEST_TIMEOUT)
|
timeout=self.DEFAULT_REQUEST_TIMEOUT)
|
||||||
|
|
||||||
def requestUpload(self, request: CloudPrintJobUploadRequest,
|
def requestUpload(self, request: CloudPrintJobUploadRequest,
|
||||||
on_finished: Callable[[CloudPrintJobResponse], Any]) -> None:
|
on_finished: Callable[[CloudPrintJobResponse], Any]) -> None:
|
||||||
|
@ -135,10 +135,10 @@ class CloudApiClient:
|
||||||
data = json.dumps({"data": request.toDict()}).encode()
|
data = json.dumps({"data": request.toDict()}).encode()
|
||||||
|
|
||||||
self._http.put(url,
|
self._http.put(url,
|
||||||
scope = self._scope,
|
scope=self._scope,
|
||||||
data = data,
|
data=data,
|
||||||
callback = self._parseCallback(on_finished, CloudPrintJobResponse),
|
callback=self._parseCallback(on_finished, CloudPrintJobResponse),
|
||||||
timeout = self.DEFAULT_REQUEST_TIMEOUT)
|
timeout=self.DEFAULT_REQUEST_TIMEOUT)
|
||||||
|
|
||||||
def uploadToolPath(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]):
|
||||||
|
@ -164,11 +164,11 @@ class CloudApiClient:
|
||||||
def requestPrint(self, cluster_id: str, job_id: str, on_finished: Callable[[CloudPrintResponse], Any], on_error) -> None:
|
def requestPrint(self, cluster_id: str, job_id: str, on_finished: Callable[[CloudPrintResponse], Any], on_error) -> None:
|
||||||
url = f"{self.CLUSTER_API_ROOT}/clusters/{cluster_id}/print/{job_id}"
|
url = f"{self.CLUSTER_API_ROOT}/clusters/{cluster_id}/print/{job_id}"
|
||||||
self._http.post(url,
|
self._http.post(url,
|
||||||
scope = self._scope,
|
scope=self._scope,
|
||||||
data = b"",
|
data=b"",
|
||||||
callback = self._parseCallback(on_finished, CloudPrintResponse),
|
callback=self._parseCallback(on_finished, CloudPrintResponse),
|
||||||
error_callback = on_error,
|
error_callback=on_error,
|
||||||
timeout = self.DEFAULT_REQUEST_TIMEOUT)
|
timeout=self.DEFAULT_REQUEST_TIMEOUT)
|
||||||
|
|
||||||
def doPrintJobAction(self, cluster_id: str, cluster_job_id: str, action: str,
|
def doPrintJobAction(self, cluster_id: str, cluster_job_id: str, action: str,
|
||||||
data: Optional[Dict[str, Any]] = None) -> None:
|
data: Optional[Dict[str, Any]] = None) -> None:
|
||||||
|
@ -178,14 +178,15 @@ class CloudApiClient:
|
||||||
:param cluster_id: The ID of the cluster.
|
:param cluster_id: The ID of the cluster.
|
||||||
:param cluster_job_id: The ID of the print job within the cluster.
|
:param cluster_job_id: The ID of the print job within the cluster.
|
||||||
:param action: The name of the action to execute.
|
:param action: The name of the action to execute.
|
||||||
|
:param data: Optional data to send with the POST request
|
||||||
"""
|
"""
|
||||||
|
|
||||||
body = json.dumps({"data": data}).encode() if data else b""
|
body = json.dumps({"data": data}).encode() if data else b""
|
||||||
url = f"{self.CLUSTER_API_ROOT}/clusters/{cluster_id}/print_jobs/{cluster_job_id}/action/{action}"
|
url = f"{self.CLUSTER_API_ROOT}/clusters/{cluster_id}/print_jobs/{cluster_job_id}/action/{action}"
|
||||||
self._http.post(url,
|
self._http.post(url,
|
||||||
scope = self._scope,
|
scope=self._scope,
|
||||||
data = body,
|
data=body,
|
||||||
timeout = self.DEFAULT_REQUEST_TIMEOUT)
|
timeout=self.DEFAULT_REQUEST_TIMEOUT)
|
||||||
|
|
||||||
def _createEmptyRequest(self, path: str, content_type: Optional[str] = "application/json") -> QNetworkRequest:
|
def _createEmptyRequest(self, path: str, content_type: Optional[str] = "application/json") -> QNetworkRequest:
|
||||||
"""We override _createEmptyRequest in order to add the user credentials.
|
"""We override _createEmptyRequest in order to add the user credentials.
|
||||||
|
@ -220,8 +221,11 @@ class CloudApiClient:
|
||||||
Logger.logException("e", "Could not parse the stardust response: %s", error.toDict())
|
Logger.logException("e", "Could not parse the stardust response: %s", error.toDict())
|
||||||
return status_code, {"errors": [error.toDict()]}
|
return status_code, {"errors": [error.toDict()]}
|
||||||
|
|
||||||
def _parseResponse(self, response: Dict[str, Any], on_finished: Union[Callable[[CloudApiClientModel], Any],
|
def _parseResponse(self,
|
||||||
Callable[[List[CloudApiClientModel]], Any]], model_class: Type[CloudApiClientModel]) -> None:
|
response: Dict[str, Any],
|
||||||
|
on_finished: Union[Callable[[CloudApiClientModel], Any],
|
||||||
|
Callable[[List[CloudApiClientModel]], Any]],
|
||||||
|
model_class: Type[CloudApiClientModel]) -> None:
|
||||||
"""Parses the given response and calls the correct callback depending on the result.
|
"""Parses the given response and calls the correct callback depending on the result.
|
||||||
|
|
||||||
:param response: The response from the server, after being converted to a dict.
|
:param response: The response from the server, after being converted to a dict.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue