checksum_generator submodule

This submodule is used to generate MD5 checksums for data and metadata files in SIP package.

It also used to create hash file, which holds all checksums with paths to the files from root of the package. For example path /home/xex/packageroot/somedir/somefile.txt will be stored as /packageroot/somedir/somefile.txt.

API

Checksum generator in format specified in LTP specification.

ltp.checksum_generator._get_required_fn(fn, root_path)[source]

Definition of the MD5 file requires, that all paths will be absolute for the package directory, not for the filesystem.

This function converts filesystem-absolute paths to package-absolute paths.

Parameters:
  • fn (str) – Local/absolute path to the file.
  • root_path (str) – Local/absolute path to the package directory.
Returns:

Package-absolute path to the file.

Return type:

str

Raises:

ValueError – When fn is absolute and root_path relative or conversely.

ltp.checksum_generator.generate_checksums(directory, blacklist=set(['info.xml']))[source]

Compute checksum for each file in directory, with exception of files specified in blacklist.

Parameters:
  • directory (str) – Absolute or relative path to the directory.
  • blacklist (list/set/tuple) – List of blacklisted filenames. Only filenames are checked, not paths!
Returns:

Dict in format {fn: md5_hash}.

Return type:

dict

Note

File paths are returned as absolute paths from package root.

Raises:UserWarning – When directory doesn’t exists.
ltp.checksum_generator.generate_hashfile(directory, blacklist=set(['info.xml']))[source]

Compute checksum for each file in directory, with exception of files specified in blacklist.

Parameters:
  • directory (str) – Absolute or relative path to the directory.
  • blacklist (list/set/tuple) – List of blacklisted filenames. Only filenames are checked, not paths!
Returns:

Content of hashfile as it is specified in ABNF specification for project.

Return type:

str