ltp.py

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

API

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

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

Parameters:prefix (str) – 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')[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:prefix (str) – Path to the directory where the root_dir will be stored.

Warning

If the root_dir exists, it is REMOVED!

Returns:list of str: root_dir, orig_dir, metadata_dir
ltp.ltp._get_localized_fn(path, root_dir)[source]

Return absolute path relative to root_dir.

When path == /home/xex/somefile.txt and root_dir == /home, returned path will be /xex/somefile.txt.

Parameters:
  • path (str) – Absolute path beginning in root_dir.
  • root_dir (str) – Absolute path containing path argument.
Returns:

Local path when root_dir is considered as root of FS.

Return type:

str

ltp.ltp._path_to_id(path)[source]

Name of the root directory is used as <packageid> in info.xml.

This function makes sure, that os.path.basename() doesn’t return blank string in case that there is / at the end of the path.

Parameters:path (str) – Path to the root directory.
Returns:Basename of the path.
Return type:str
ltp.ltp._calc_dir_size(path)[source]

Calculate size of all files in path.

Parameters:path (str) – Path to the directory.
Returns:Size of the directory in bytes.
Return type:int
ltp.ltp._add_order(inp_dict)[source]

Add order to unordered dict.

Order is taken from priority table, which is just something I did to make outputs from xmltodict look like examples in specification.

Parameters:inp_dict (dict) – Unordered dictionary.
Returns:Dictionary ordered by priority table.
Return type:OrderedDict
ltp.ltp._compose_info(root_dir, files, hash_fn, aleph_record)[source]

Compose info XML file.

Info example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<info>
    <created>2014-07-31T10:58:53</created>
    <metadataversion>1.0</metadataversion>
    <packageid>c88f5a50-7b34-11e2-b930-005056827e51</packageid>
    <mainmets>mets.xml</mainmets>
    <titleid type="ccnb">cnb001852189</titleid>
    <titleid type="isbn">978-80-85979-89-6</titleid>
    <collection>edeposit</collection>
    <institution>nakladatelství Altar</institution>
    <creator>ABA001</creator>
    <size>1530226</size>
    <itemlist itemtotal="1">
        <item>\data\Denik_zajatce_Sramek_CZ_v30f-font.epub</item>
    </itemlist>
    <checksum type="MD5" checksum="ce076548eaade33888005de5d4634a0d">
        \MD5.md5
    </checksum>
</info>
Parameters:
  • root_dir (str) – Absolute path to the root directory.
  • original_fn (str) – Absolute path to the ebook file.
  • metadata_fn (str) – Absolute path to the metadata file.
  • hash_fn (str) – Absolute path to the MD5 file.
  • aleph_record (str) – String with Aleph record with metadata.
Returns:

XML string.

Return type:

str

ltp.ltp.create_ltp_package(aleph_record, book_id, ebook_fn, b64_data)[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 (int) – More or less unique ID of the book.
  • ebook_fn (str) – Original filename of the ebook.
  • b64_data (str) – Ebook file encoded in base64 string.
Returns:

Name of the package’s directory in /tmp.

Return type:

str

Table Of Contents

Previous topic

xslt_transformer submodule

Next topic

fn_composers submodule

This Page