class documentation

A database engine that can be subclassed for different Gallery providers.

Method __init__ Initialise the database engine.
Method add Add an item to the gallery database.
Method delete Delete an item from the gallery database.
Method dispose Dispose of the active connections for this database engine.
Method entry_to_base_model Convert GalleryEntry to GalleryEntryModel.
Method fullpath_to_normpath Convert the abs native path to the relative posix path for the database.
Method get Get a single item from the gallery database.
Method get_all_entries Get a list of all Gallery Entries.
Method get_all_entries_as_base_model Get a list of entries as a base model for the API.
Method get_all_paths Get a list of the paths for all gallery items.
Method normpath_to_fullpath Convert the relative posix path from the database to the abs native path.
Method rebuild Rebuild a single gallery entry as it has changed on disk.
Method session Yield a database session. Commit on completion, rollback on error.
Method sync_db_with_file_system Sync the database with the file system.
Class Variable card_type Undocumented
Class Variable gallery_info_model Undocumented
Method _delete_endpoint Return the endpoint for deleting an entry (relative to the base URL).
Method _generate_entry Create a GalleryEntry for an item based on the data on disk.
Method _hash Create a unique hash for an item.
Method _list_all_items_on_file_system List all the items on this file system.
Method _mounted_path Return the mount point for the normalised path.
Instance Variable _data_dir Undocumented
Instance Variable _engine Undocumented
Instance Variable _thing Undocumented
def __init__(self, data_dir: str, thing: lt.Thing): (source)

Initialise the database engine.

Parameters
data_dir:strThe directory of the data.
thing:lt.ThingThe thing that is managing this data source.
def add(self, path: str | RelativeDataPath): (source)

Add an item to the gallery database.

This should be called when an item is added to disk.

def delete(self, path: str) -> bool: (source)

Delete an item from the gallery database.

def dispose(self): (source)

Dispose of the active connections for this database engine.

def entry_to_base_model(self, entry: GalleryEntry) -> GalleryEntryModel: (source)

Convert GalleryEntry to GalleryEntryModel.

def fullpath_to_normpath(self, fullpath: str) -> str: (source)

Convert the abs native path to the relative posix path for the database.

The database requires normalised POSIX paths.

def get(self, path: str) -> GalleryEntry | None: (source)

Get a single item from the gallery database.

Parameters
path:strThe normalised relative posixpath for the requested entry.
Returns
GalleryEntry | NoneThe GalleryEntry that matches the path, or None if nothing matches.
def get_all_entries(self) -> list[GalleryEntry]: (source)

Get a list of all Gallery Entries.

def get_all_entries_as_base_model(self) -> list[GalleryEntryModel]: (source)

Get a list of entries as a base model for the API.

def get_all_paths(self) -> list[str]: (source)

Get a list of the paths for all gallery items.

def normpath_to_fullpath(self, normpath: str) -> str: (source)

Convert the relative posix path from the database to the abs native path.

def rebuild(self, path: str, ignore_missing: bool = False): (source)

Rebuild a single gallery entry as it has changed on disk.

@contextmanager
def session(self, write: bool) -> Iterator[orm.Session]: (source)

Yield a database session. Commit on completion, rollback on error.

def sync_db_with_file_system(self): (source)

Sync the database with the file system.

This is run when the microscope first loads. It can also be manually called if the data is changed on disk. It shouldn't be needed in other situations.

gallery_info_model: type[BaseModel] = (source)

Undocumented

@abstractmethod
def _delete_endpoint(self, path: str) -> str: (source)

Return the endpoint for deleting an entry (relative to the base URL).

Parameters
path:strThe normalised relative posixpath for the item. This is the primary key of the GalleryEntry table.
Returns
strUndocumented
@abstractmethod
def _generate_entry(self, path: str, gallery_added_data: dict | None = None) -> GalleryEntry: (source)

Create a GalleryEntry for an item based on the data on disk.

Parameters
path:strThe normalised relative posixpath for the item. This is the primary key of the GalleryEntry table.
gallery_added_data:dict | NoneAny data added by the gallery. This can be used to persist gallery added data even if item is modified on disk.
Returns
GalleryEntryA GalleryEntry for the item.
@abstractmethod
def _hash(self, path: str) -> str: (source)

Create a unique hash for an item.

For images in the gallery this is just checking the image has not been updated or replaced. For speed we use a blake2b 8-byte hash of the file size and the modified time.

Parameters
path:strThe normalised relative posixpath for the item to hash. This is the primary key of the GalleryEntry table.
Returns
strA unique identifier to check if the item has changed. For large items that are a folder of data it is not recommended to hash the entire file as this is slow. Instead, hash just enough information about the item to confirm that it's unchanged.
@abstractmethod
def _list_all_items_on_file_system(self) -> list[str]: (source)

List all the items on this file system.

Returns
list[str]A list of paths.
@abstractmethod
def _mounted_path(self, path: str) -> str: (source)

Return the mount point for the normalised path.

This may be the mount point for an entry or another file in the data directory.

Parameters
path:strThe normalised relative posixpath for the item. This is the primary key of the GalleryEntry table.
Returns
strUndocumented
_data_dir = (source)

Undocumented

Undocumented

Undocumented