Skip to content

component

component

Component

Component(client: Client, data: dict[str, Any])

Component model

Source code in src/itkdb/models/component.py
def __init__(self, client: Client, data: dict[str, Any]):
    self._client = client
    self._data = data
    self._children: list[Any] = []

children property writable

children: list[Any]

children of component

id property

id: str

unique identifier of component

serial_number property

serial_number: str

serial number of component

__repr__

__repr__() -> str
Source code in src/itkdb/models/component.py
def __repr__(self) -> str:
    module = type(self).__module__
    qualname = type(self).__qualname__
    return f"<{module}.{qualname} object '{self.serial_number}' at {hex(id(self))}>"

walk

walk(recurse: bool = True) -> None

recursively walk through children and load information from database

Source code in src/itkdb/models/component.py
def walk(self, recurse: bool = True) -> None:
    """recursively walk through children and load information from database"""
    for child in self.children:
        # BadRequest: component doesn't exist
        # KeyError: no component in slot
        data = child
        with suppress(BadRequest, KeyError):
            data = self._client.get(  # type: ignore[no-untyped-call]
                "getComponent", json={"component": child["component"]["id"]}
            )

        child_component = Component(self._client, data)
        if recurse:
            child_component.walk(recurse)
        self._children.append(child_component)