Skip to content

value

Attributes

logger = structlog.getLogger() module-attribute

Classes

StoreValueResult

Bases: BaseModel

Source code in kiara/interfaces/python_api/value.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class StoreValueResult(BaseModel):

    value: Value = Field(description="The stored value.")
    aliases: List[str] = Field(
        description="The aliases that where assigned to the value when stored."
    )
    persisted_data: Union[None, PersistedData] = Field(
        description="The structure describing the data that was persisted, 'None' if the data was already stored before (or storing failed)."
    )
    error: Union[str, None] = Field(
        description="An error that occured while trying to store."
    )

    def _repr_html_(self):

        r = self.create_renderable()
        mime_bundle = r._repr_mimebundle_(include=[], exclude=[])  # type: ignore
        return mime_bundle["text/html"]

    def __rich_console__(
        self, console: Console, options: ConsoleOptions
    ) -> RenderResult:

        yield self.create_renderable()

    def create_renderable(self, **config) -> RenderableType:

        table = Table(show_header=False, box=box.SIMPLE)
        table.add_column("key", "i")
        table.add_column("value")

        table.add_row("value_id", str(self.value.value_id))
        if self.aliases:
            if len(self.aliases) > 1:
                a = "aliases"
            else:
                a = "alias"
            table.add_row(a, ", ".join(self.aliases))
        else:
            table.add_row("aliases", "-- no aliases --")
        table.add_row("data type", self.value.data_type_name)
        table.add_row("size", humanfriendly.format_size(self.value.value_size))
        table.add_row("success", "yes" if not self.error else "no")
        if self.error:
            table.add_row("[red]error[/red]", f"{self.error}")

        return Panel(table, title="Store operation result", title_align="left")

Attributes

value: Value = Field(description='The stored value.') class-attribute
aliases: List[str] = Field(description='The aliases that where assigned to the value when stored.') class-attribute
persisted_data: Union[None, PersistedData] = Field(description="The structure describing the data that was persisted, 'None' if the data was already stored before (or storing failed).") class-attribute
error: Union[str, None] = Field(description='An error that occured while trying to store.') class-attribute

Functions

create_renderable(**config) -> RenderableType
Source code in kiara/interfaces/python_api/value.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def create_renderable(self, **config) -> RenderableType:

    table = Table(show_header=False, box=box.SIMPLE)
    table.add_column("key", "i")
    table.add_column("value")

    table.add_row("value_id", str(self.value.value_id))
    if self.aliases:
        if len(self.aliases) > 1:
            a = "aliases"
        else:
            a = "alias"
        table.add_row(a, ", ".join(self.aliases))
    else:
        table.add_row("aliases", "-- no aliases --")
    table.add_row("data type", self.value.data_type_name)
    table.add_row("size", humanfriendly.format_size(self.value.value_size))
    table.add_row("success", "yes" if not self.error else "no")
    if self.error:
        table.add_row("[red]error[/red]", f"{self.error}")

    return Panel(table, title="Store operation result", title_align="left")

StoreValuesResult

Bases: BaseModel

Source code in kiara/interfaces/python_api/value.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class StoreValuesResult(BaseModel):

    __root__: Dict[str, StoreValueResult]

    def create_renderable(self, **config: Any) -> RenderableType:

        table = Table(show_header=True, show_lines=False, box=box.SIMPLE)
        table.add_column("field", style="b")
        table.add_column("data type", style="i")
        table.add_column("stored id", style="i")
        table.add_column("alias(es)")

        for field_name, value_result in self.__root__.items():
            row = [
                field_name,
                str(value_result.value.value_schema.type),
                str(value_result.value.value_id),
            ]
            if value_result.aliases:
                row.append(", ".join(value_result.aliases))
            else:
                row.append("")
            table.add_row(*row)

        return table

    def __len__(self):
        return len(self.__root__)

Functions

create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/value.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def create_renderable(self, **config: Any) -> RenderableType:

    table = Table(show_header=True, show_lines=False, box=box.SIMPLE)
    table.add_column("field", style="b")
    table.add_column("data type", style="i")
    table.add_column("stored id", style="i")
    table.add_column("alias(es)")

    for field_name, value_result in self.__root__.items():
        row = [
            field_name,
            str(value_result.value.value_schema.type),
            str(value_result.value.value_id),
        ]
        if value_result.aliases:
            row.append(", ".join(value_result.aliases))
        else:
            row.append("")
        table.add_row(*row)

    return table