salvus.project.components.attachment_component
The attachment component for SalvusProject.
Allows one to attach any file up to a size limit in a Salvus project.
Classes
AttachmentComponent
AttachmentComponentclass AttachmentComponent(builtins.object):
def __init__(self, project: Project, path: pathlib.Path): ...Project subclass handling attachments to a project.
Parameters
projectProject — The project.pathpathlib.Path — Path to the attachment folder.
Methods
add()
add()def add(
self,
name: str,
content: bytes | str | dict,
overwrite: bool = False,
description: str | None = None,
) -> None: ...Add an attachment to the project.
Parameters
namestr — Name of the file.contentbytes | str | dict — Content of the file.overwritebool — Whether to overwrite the file if it already exists.descriptionstr | None — An optional description of the file.
Returns None
delete()
delete()def delete(self, name: str) -> None: ...Delete an attachment from disk and the project.
Parameters
namestr — Name of the attachment to delete.
Returns None
detail_list()
detail_list()def detail_list(self) -> typing.List[dict]: ...List all attachments details.
Listed information is: - description; - size_in_bytes; - mime_type; - added_at.
Returns typing.List[dict]
get_content()
get_content()def get_content(self, name: str) -> bytes: ...Get the content of an attachment as bytes.
Parameters
namestr — Name of the attachment.
Returns bytes
get_content_dict()
get_content_dict()def get_content_dict(self, name: str) -> dict: ...Get the content of an attachment as a dictionary.
Only a limited set of file types (json) can be retrieved as dictionaries.
Parameters
namestr — Name of the attachment.
Returns dict
get_content_str()
get_content_str()def get_content_str(self, name: str) -> str: ...Get the content of an attachment as a string.
Only a limited set of file types (plaintext, markdown) can be retrieved as strings.
Parameters
namestr — Name of the attachment.
Returns str
get_details()
get_details()def get_details(self, name: str) -> dict: ...Get details of an attachment.
Parameters
namestr — Name of the attachment.
Returns dict
list()
list()def list(self) -> list[str]: ...List all attachments.
Returns list[str]