ltp.py

This module contains functions to create SIP package for the LTP system.

API

ltp.ltp._get_package_name(prefix='/tmp', book_id=None)[source]

Return package path. Use uuid to generate package’s directory name.

Parameters:
  • book_id (str, default None) – UUID of the book.
  • prefix (str, default settings.TEMP_DIR) – Where the package will be stored. Default settings.TEMP_DIR.
Returns:

Path to the root directory.

Return type:

str

ltp.ltp._create_package_hierarchy(prefix='/tmp', book_id=None)[source]

Create hierarchy of directories, at it is required in specification.

root_dir is root of the package generated using settings.TEMP_DIR and _get_package_name().

orig_dir is path to the directory, where the data files are stored.

metadata_dir is path to the directory with MODS metadata.

Parameters:
  • book_id (str, default None) – UUID of the book.
  • prefix (str, default settings.TEMP_DIR) – Where the package will be stored. Default settings.TEMP_DIR.

Warning

If the root_dir exists, it is REMOVED!

Returns:root_dir, orig_dir, metadata_dir
Return type:list of str
ltp.ltp.create_ltp_package(aleph_record, book_id, ebook_fn, data, url, urn_nbn=None)[source]

Create LTP package as it is specified in specification v1.0 as I understand it.

Parameters:
  • aleph_record (str) – XML containing full aleph record.
  • book_id (str) – UUID of the book.
  • ebook_fn (str) – Original filename of the ebook.
  • data (str/bytes) – Ebook’s content.
  • url (str) – URL of the publication used when the URL can’t be found in aleph_record.
  • urn_nbn (str, default None) – URN:NBN.
Returns:

Name of the package’s directory in /tmp.

Return type:

str