ocfl.Version
The ocfl.Version class is used only in conjunction with the ocfl.Inventory class as it simply provides a convenient access point into the data of an ocfl.Inventory.
- class ocfl.Version(inv, vdir)
Version class to represent version information in an Inventory.
The class stores only pointers to the appropriate ocfl.Inventory object and the version directory key within the versions block. These are used to access and manipulate data for a specific version in the inventory.
- __init__(inv, vdir)
Initialize Version object.
- Parameters:
inv – Inventory object for which this is one version.
vdir – Version directory string for the version of interest.
- add_file(*, digest, logical_path, content_path=None, dedupe=True)
Add information for a file with given digest in this version.
- Parameters:
digest – the file digest that must be created using the appropriate digestAlgorithm.
logical_path – path within the state for this version.
content_path – local content path to be used if a file is created within this version. If not specified then the logical_path name will be used as the basis.
dedupe – bool, True (default) to not add files for which there is already a file with the same digest, False to add anyway
Returns the full content path (including vdir and content directory) of the file added, else None if no file was added. Makes changes to both the state for this version and the inventory manifest.
Raises an InventoryException if there is an attempt to add a logical path that already exists in this version.
- content_path_for_logical_path(path)
Content path for the file in this version for the logical path.
Note that there could be more than one content path with the digest. Here we just return the first one. Returns None if there no matching content path.
- property created
Created string for this version.
- delete_logical_path(path)
Delete the given logical path in this version.
Will remove the logical path, and possibly the state entry for its digest if there was only one logical path for the given digest.
If this is the last reference to a given digest in the current version state then delete any content files in this version for the given digest. (There is the possibility of odd behavior if dedupe is set False so that multiple copies are created within the version – all copies will be left until the last reference is deleted, then all copies will be deleted.)
- Parameters:
path – path within the state for this version
- Returns:
digest of the content for which the logical path was removed
- Return type:
str
- Raises:
InventoryException – if the logical path does not exist
- digest_for_logical_path(path)
Digest for the given logical path in this version.
Return digest string or None is path not found.
- property logical_paths
List of the logical paths in this version.
Returns a list, will be empty if there are no logical paths.
- property message
Message string for this verion.
- property number
Version number for this version.
See also vdir attribute for version directory name.
- property state
State block for this version.
Returns a dict for the state block or and empty dict if there is no state block.
- state_add_if_not_present()
State block for this version, adding an empty one if not present.
Returns a dict for the state block. As a side effect will create an empty dict in the data structure if none was present, so that new data can be added by assignment.
Example
>>> ver.state_add_if_not_present()[digest] = [logical_path]
- property user
User block for this version.
- user_add_if_not_present()
User block for this version, add if not present.
- property user_address
Address element in the user description for this version.
Returns a string or None is there is no name.
- property user_name
Name element in the user description for this version.
Returns a string or None is there is no name.