Skip to content

Utils

The utils module

gamslib.objectcsv.utils

Utility functions for the objectcsv module.

Provides helpers for finding object folders, extracting titles from TEI and LIDO files, and splitting CSV entries into lists.

logger module-attribute

logger = logging.getLogger()

split_entry

split_entry(entry)

Split a string of CSV entries into a list using semicolon as delimiter.

PARAMETER DESCRIPTION
entry

String containing CSV entries separated by semicolons.

TYPE: str

RETURNS DESCRIPTION
list[str]

list[str]: List of trimmed entries. Returns an empty list if entry is empty.

Notes
  • Leading and trailing whitespace is removed from each entry.
  • Only non-empty entries are included in the result.

extract_title_from_tei

extract_title_from_tei(tei_file)

Extract the title from a TEI file.

PARAMETER DESCRIPTION
tei_file

Path to the TEI XML file.

TYPE: Path or str

RETURNS DESCRIPTION
str

Title extracted from the TEI file, or an empty string if not found.

TYPE: str

extract_title_from_lido

extract_title_from_lido(lido_file)

Extract the title from a LIDO file.

PARAMETER DESCRIPTION
lido_file

Path to the LIDO XML file.

TYPE: Path or str

RETURNS DESCRIPTION
str

Title extracted from the LIDO file, or an empty string if not found.

TYPE: str

find_object_root

find_object_root(start_path)

Find the root folder of an object by searching for DC.XML.

PARAMETER DESCRIPTION
start_path

The path to start searching from.

TYPE: Path

RETURNS DESCRIPTION
Path

The root folder of the object.

TYPE: Path

Raises: FileNotFoundError: If no DC.XML file is found in the current or parent directories

distinctify

distinctify(values)

Remove duplicate values from a semicolon-separated string.