ocfl.StorageRoot

OCFL Storage Root library.

This code uses PyFilesystem (import fs) exclusively for access to files. This should enable application beyond the operating system filesystem.

class ocfl.StorageRoot(root=None, layout_name=None, lax_digests=False, spec_version=None)

Class for handling OCFL Storage Root and include OCFL Objects.

__init__(root=None, layout_name=None, lax_digests=False, spec_version=None)

Initialize OCFL Storage Root.

add(object_path)

Add pre-constructed object from object_path.

The identifier is extracted from the object and the path is determined by the storage layouts

Return the (identifier, path) on success, raises a StorageException on failure.

check_root_structure()

Check the OCFL storage root structure.

Assumed that self.root_fs filesystem is available. Raises StorageRootException if there is an error.

check_spec_version(spec_version, default='1.1')

Check the OCFL specification version is supported.

initialize(spec_version=None, layout_params=None)

Create and initialize a new OCFL storage root.

property layout

Instance of layout class.

Lazily initialized. Will return either a valid layout name or None if the layout is not set.

list_objects()

List contents of this OCFL storage root.

Generator that yields tuple for each object, which contain (dirpath, identifier)

Side effects: The count of num_objects is updated through the taversal of the storage root and is available afterwards.

object_path(identifier)

Path to OCFL object with given identifier relative to the OCFL storage root.

object_paths()

Generate object paths for every obect in the OCFL storage root.

Yields (dirpath) that is the path to the directory for each object located, relative to the OCFL storage root and without a preceding /.

Will log any errors seen while traversing the directory tree under the storage root.

open_root_fs(create=False)

Open pyfs filesystem for this OCFL storage root.

parse_layout_file()

Read and parse layout file in OCFL storage root.

Returns:

  • (extension, description) strings on success,

  • otherwise raises a StorageRootException.

root_declaration_object()

NAMASTE object declaration Namaste object.

traversal_error(code, **kwargs)

Record error traversing OCFL storage root.

validate(*, validate_objects=True, check_digests=True, log_warnings=False, log_errors=True, max_errors=100, lang='en')

Validate OCFL storage root, structure, and optionally all objects.

Parameters:
  • validate_objects (bool) – True (default) to validate each object on the storage root, otherwise will not validate the objects

  • check_digests (bool) – True (default) to check the digests of each file while validating objects

  • log_warnings (bool) – True if warnings should be logged, default False

  • log_errors (bool) – True (default) if errors should be logged

  • max_errors (int) – Number of errors and warnings to log, default is 100

  • lang (str) – Language of error and warning descriptions to look for, default is “en”

Returns True if everything checked is valid, False otherwise.

Side effects:

self.num_objects - number of objects examined self.good_objects - number of valid objects self.errors - list of [dirpath, message] pairs for up to max_errors errors self.structure_error - Error in storage root structure self.log - ValidationLogger object with any traversal errors

validate_extensions_dir()

Validate content of extensions directory inside storage root.

Validate the extensions directory by checking that there aren’t any entries in the extensions directory that aren’t directories themselves. Where there are extension directories they SHOULD be registered and this code relies up the registered_extensions property to list known storage root extensions.

validate_hierarchy(validate_objects=True, check_digests=True, log_warnings=False, max_errors=100)

Validate storage root hierarchy and, optionally, all objects.

Returns:

num_objects - number of objects checked good_objects - number of objects checked that were found to be valid errors - list of [dirpath, message] pairs for up to max_errors errors

write_root_declaration(root_fs)

Write NAMASTE object declaration.

Assumes self.obj_fs is open for this object.

class ocfl.StorageRootException

Exception class for OCFL Storage Root.