Skip to content

store

mlte/store/catalog/store.py

MLTE catalog store interface implementation.

CatalogEntryMapper

Bases: ResourceMapper

A interface for mapping CRUD actions to store entries.

Source code in mlte/store/catalog/store.py
57
58
59
60
61
62
63
64
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
93
94
95
class CatalogEntryMapper(ResourceMapper):
    """A interface for mapping CRUD actions to store entries."""

    def create(self, entry: CatalogEntry, context: Any = None) -> CatalogEntry:
        raise NotImplementedError(self.NOT_IMPLEMENTED_ERROR_MSG)

    def edit(self, entry: CatalogEntry, context: Any = None) -> CatalogEntry:
        raise NotImplementedError(self.NOT_IMPLEMENTED_ERROR_MSG)

    def read(self, entry_id: str, context: Any = None) -> CatalogEntry:
        raise NotImplementedError(self.NOT_IMPLEMENTED_ERROR_MSG)

    def list(self, context: Any = None) -> typing.List[str]:
        raise NotImplementedError(self.NOT_IMPLEMENTED_ERROR_MSG)

    def delete(self, entry_id: str, context: Any = None) -> CatalogEntry:
        raise NotImplementedError(self.NOT_IMPLEMENTED_ERROR_MSG)

    def create_with_header(
        self,
        entry: CatalogEntry,
        context: Any = None,
        user: typing.Optional[str] = None,
    ) -> CatalogEntry:
        """Create an entry, generating the timestamp and adding creator. Internally calls the appropriate create implementation."""
        entry.header.created = int(time.time())
        entry.header.creator = user
        return self.create(entry, context)

    def edit_with_header(
        self,
        entry: CatalogEntry,
        context: Any = None,
        user: typing.Optional[str] = None,
    ) -> CatalogEntry:
        """Edit an entry, generating the proper timestamp. Internally calls the appropriate create implementation."""
        entry.header.updated = int(time.time())
        entry.header.updater = user
        return self.edit(entry, context)

create_with_header(entry, context=None, user=None)

Create an entry, generating the timestamp and adding creator. Internally calls the appropriate create implementation.

Source code in mlte/store/catalog/store.py
75
76
77
78
79
80
81
82
83
84
def create_with_header(
    self,
    entry: CatalogEntry,
    context: Any = None,
    user: typing.Optional[str] = None,
) -> CatalogEntry:
    """Create an entry, generating the timestamp and adding creator. Internally calls the appropriate create implementation."""
    entry.header.created = int(time.time())
    entry.header.creator = user
    return self.create(entry, context)

edit_with_header(entry, context=None, user=None)

Edit an entry, generating the proper timestamp. Internally calls the appropriate create implementation.

Source code in mlte/store/catalog/store.py
86
87
88
89
90
91
92
93
94
95
def edit_with_header(
    self,
    entry: CatalogEntry,
    context: Any = None,
    user: typing.Optional[str] = None,
) -> CatalogEntry:
    """Edit an entry, generating the proper timestamp. Internally calls the appropriate create implementation."""
    entry.header.updated = int(time.time())
    entry.header.updater = user
    return self.edit(entry, context)

CatalogStore

Bases: Store

Source code in mlte/store/catalog/store.py
24
25
26
27
28
29
30
class CatalogStore(Store):
    read_only: bool = False
    """Whether this catalog is read only or not."""

    def session(self) -> CatalogStoreSession:
        """Return a session handle for a catalog store session instance."""
        raise NotImplementedError("Can't call session on a base Store.")

read_only = False class-attribute instance-attribute

Whether this catalog is read only or not.

session()

Return a session handle for a catalog store session instance.

Source code in mlte/store/catalog/store.py
28
29
30
def session(self) -> CatalogStoreSession:
    """Return a session handle for a catalog store session instance."""
    raise NotImplementedError("Can't call session on a base Store.")

CatalogStoreSession

Bases: StoreSession

The base class for all implementations of the MLTE catalog store session.

Source code in mlte/store/catalog/store.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class CatalogStoreSession(StoreSession):
    """The base class for all implementations of the MLTE catalog store session."""

    entry_mapper: CatalogEntryMapper
    """Mapper for the entry resource."""

    read_only: bool = False
    """Whether this session is read only or not."""

    storage: Storage
    """The underlying storage method."""

    def get_uri(self) -> StoreURI:
        """Returns the URI of the store."""
        return self.storage.get_uri()

entry_mapper instance-attribute

Mapper for the entry resource.

read_only = False class-attribute instance-attribute

Whether this session is read only or not.

storage instance-attribute

The underlying storage method.

get_uri()

Returns the URI of the store.

Source code in mlte/store/catalog/store.py
45
46
47
def get_uri(self) -> StoreURI:
    """Returns the URI of the store."""
    return self.storage.get_uri()

ManagedCatalogSession

Bases: ManagedSession

A simple context manager for store sessions.

Source code in mlte/store/catalog/store.py
50
51
52
53
54
class ManagedCatalogSession(ManagedSession):
    """A simple context manager for store sessions."""

    def __enter__(self) -> CatalogStoreSession:
        return typing.cast(CatalogStoreSession, self.session)