cata_log_hub.database.models module

class cata_log_hub.database.models.ModelBase[source]

Bases: DeclarativeBase

Base for all ORM models.

metadata: ClassVar[MetaData] = MetaData()

Refers to the _schema.MetaData collection that will be used for new _schema.Table objects.

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

Parameters:
Return type:

None

registry: ClassVar[registry] = <sqlalchemy.orm.decl_api.registry object>

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

class cata_log_hub.database.models.Provider[source]

Bases: ModelBase, TimestampMixin

ORM model for a catalog provider.

id: Mapped[int]
class_uid: Mapped[str]
configuration: Mapped[dict[str, str]]
note: Mapped[str]
job_id: Mapped[str | None]
catalogs: Mapped[list[Catalog]]
status: Mapped[StatusEnum]
get_provider_class()[source]

Get the class for this provider.

Return type:

type[Provider]

Returns:

The provider class.

Raises:

cata_log_hub.exceptions.ProviderUnknownClassWarning – If there is no class for this provider’s class-uid.

get_provider_instance()[source]

Get a class instance for this provider.

Return type:

Provider

Returns:

The provider instance.

Raises:

cata_log_hub.exceptions.ProviderUnknownClassWarning – If there is no class for this provider’s class-uid.

fetch_catalog(db_session)[source]

Fetch this provider’s catalog and save it to storage and db.

Raises:

cata_log_hub.exceptions.NetworkError – Reraised

Return type:

None

Parameters:

db_session (Session)

add_job()[source]

Add the job for this provider.

Return type:

None

remove_job()[source]

Remove the job of this provider.

Return type:

None

property job: Job | None

The job of this provider.

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

created_at: Mapped[datetime]
updated_at: Mapped[datetime]
class cata_log_hub.database.models.Catalog[source]

Bases: ModelBase, TimestampMixin

ORM model for a catalog.

id: Mapped[int]
valid_since: Mapped[datetime]
valid_until: Mapped[datetime]
provider: Mapped[Provider]
provider_id: Mapped[int]
pages: Mapped[list[Page]]
as_pdf()[source]

Compress the catalog to a pdf file.

Return type:

bytes

Returns:

The pdf file bytes.

as_epub()[source]

Convert the catalog to a epub file.

Return type:

bytes

Returns:

The epub file bytes.

classmethod cleanup(db_session, deadline)[source]

Cleanup catalogs created before a deadline.

Parameters:
  • db_session (Session) – A database session.

  • deadline (datetime) – The deadline for catalog deletion.

Return type:

None

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

created_at: Mapped[datetime]
updated_at: Mapped[datetime]
class cata_log_hub.database.models.PageFile[source]

Bases: ModelBase, TimestampMixin

ORM model for a catalog page file.

id: Mapped[int]
path: Mapped[Path]
original_sha256: Mapped[str]
sha256: Mapped[str]
size: Mapped[int]
height: Mapped[int]
width: Mapped[int]
pages: Mapped[list[Page]]
validate_nonnegative_number(key, value)[source]

Ensure size values are positive.

Return type:

int

Parameters:
property name: str

The name of the stored file.

classmethod get_or_create(db_session, page_bytes)[source]

Get or create a pagefile.

Parameters:
  • db_session (Session) – A database session to use.

  • page_bytes (bytes) – The content of the pagefile.

  • path – The path for the pagefile.

Return type:

PageFile

classmethod cleanup(db_session)[source]

Cleanup unused page files.

Parameters:

db_session (Session) – A database session.

Return type:

None

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

created_at: Mapped[datetime]
updated_at: Mapped[datetime]
class cata_log_hub.database.models.Page[source]

Bases: ModelBase, TimestampMixin

ORM model for a catalog page.

id: Mapped[int]
number: Mapped[int]
catalog_id: Mapped[int]
catalog: Mapped[Catalog]
file_id: Mapped[int]
file: Mapped[PageFile]
validate_nonnegative_number(key, number)[source]

Ensure number is nonnegative.

Return type:

int

Parameters:
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

created_at: Mapped[datetime]
updated_at: Mapped[datetime]