Searching container registry returns ContainerStacks.

Made typing more generic to work with an ContainerStack to compensate.

Made AbstractMachine getMachines a classmethod so it can be called with ContainerStacks.

CURA-9514
This commit is contained in:
joeydelarago 2022-08-23 10:35:00 +02:00
parent d1ae3136aa
commit 7ffa770fb4
4 changed files with 22 additions and 6 deletions

View file

@ -14,13 +14,22 @@ class AbstractMachine(GlobalStack):
super().__init__(container_id)
self.setMetaDataEntry("type", "abstract_machine")
def getMachines(self) -> List[ContainerStack]:
from cura.CuraApplication import CuraApplication
@classmethod
def getMachines(cls, abstract_machine: ContainerStack) -> List[ContainerStack]:
""" Fetches containers for all machines that match definition with an abstract machine.
:param abstractMachine: The abstract machine stack.
:return: A list of Containers or an empty list if stack is not an "abstract_machine"
"""
if not abstract_machine.getMetaDataEntry("type") == "abstract_machine":
return []
from cura.CuraApplication import CuraApplication # In function to avoid circular import
application = CuraApplication.getInstance()
registry = application.getContainerRegistry()
printer_type = self.definition.getId()
printer_type = abstract_machine.definition.getId()
return [machine for machine in registry.findContainerStacks(type="machine") if machine.definition.id == printer_type and ConnectionType.CloudConnection in machine.configuredConnectionTypes]