The utils module¶
This module provides some utility function needed when dealing with GAMS bags.
gamslib.sip.utils
¶
Utility functions for the GAMS SIP package creation and validation.
Provides helpers for validating object directories, extracting IDs, calculating hashes, counting files and bytes, and fetching JSON schemas for validation.
Features
- Validates object directory structure and required files.
- Extracts and validates object and datastream IDs.
- Calculates MD5, SHA512 hashes for files.
- Counts files and bytes in a directory tree.
Usage
Use validate_object_dir(object_path) to check an object directory.
Use extract_id(path) to extract and validate an object or datastream ID.
Use md5hash(file), sha512hash(file), or sha256hash(file) for file checksums.
Use count_bytes(root_dir) or count_files(root_dir) for directory statistics.
count_bytes
¶
count_files
¶
fetch_json_schema
cached
¶
Fetch a JSON schema from a URL.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
URL to fetch the JSON schema from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Parsed JSON schema.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
BagValidationError
|
If the schema cannot be fetched or is not valid JSON. |
is_bag
¶
Check if the given path points to a Bag.
It does not check the validity of the Bag, only if the structure indicates that it looks like a Bag.
bag_path can be either a directory or a file (zip).
| PARAMETER | DESCRIPTION |
|---|---|
bag_path
|
The path to the directory to check.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the path points to a Bag, False otherwise.
TYPE:
|