Merge branch 'master' of github.com:Ultimaker/Cura into CURA-7090-addition

This commit is contained in:
Dimitriovski 2020-01-21 15:08:24 +01:00
commit 369329c476
No known key found for this signature in database
GPG key ID: 4E62757E2B0D304D
10 changed files with 120 additions and 15 deletions

View file

@ -18,3 +18,11 @@ class CloudApiModel:
cloud_api_root=cloud_api_root,
cloud_api_version=cloud_api_version,
)
## https://api.ultimaker.com/cura-packages/v1/user/packages/{package_id}
@classmethod
def userPackageUrl(cls, package_id: str) -> str:
return (CloudApiModel.api_url_user_packages + "/{package_id}").format(
package_id=package_id
)

View file

@ -16,3 +16,8 @@ class CloudPackageManager:
data=data.encode(),
scope=self._scope
)
def unsubscribe(self, package_id: str) -> None:
url = CloudApiModel.userPackageUrl(package_id)
self._request_manager.delete(url=url, scope=self._scope)

View file

@ -1,8 +1,10 @@
import os
from typing import List, Dict, Any, cast
from UM import i18n_catalog
from UM.Extension import Extension
from UM.Logger import Logger
from UM.Message import Message
from UM.PluginRegistry import PluginRegistry
from cura.CuraApplication import CuraApplication
from .CloudPackageChecker import CloudPackageChecker
@ -64,7 +66,10 @@ class SyncOrchestrator(Extension):
# \param success_items: Dict[package_id, file_path]
# \param error_items: List[package_id]
def _onDownloadFinished(self, success_items: Dict[str, str], error_items: List[str]) -> None:
# todo handle error items
if error_items:
message = i18n_catalog.i18nc("@info:generic", "{} plugins failed to download".format(len(error_items)))
self._showErrorMessage(message)
plugin_path = cast(str, PluginRegistry.getInstance().getPluginPath(self.getPluginId()))
self._license_presenter.present(plugin_path, success_items)
@ -78,15 +83,20 @@ class SyncOrchestrator(Extension):
if item["accepted"]:
# install and subscribe packages
if not self._package_manager.installPackage(item["package_path"]):
Logger.error("could not install {}".format(item["package_id"]))
message = "Could not install {}".format(item["package_id"])
self._showErrorMessage(message)
continue
self._cloud_package_manager.subscribe(item["package_id"])
has_changes = True
else:
# todo unsubscribe declined packages
pass
self._cloud_package_manager.unsubscribe(item["package_id"])
# delete temp file
os.remove(item["package_path"])
if has_changes:
self._restart_presenter.present()
## Logs an error and shows it to the user
def _showErrorMessage(self, text: str):
Logger.error(text)
Message(text, lifetime=0).show()