Pywrapid Utils
Documentaiton coming soon
Dict tools
Collection of helper functions
- dict_keys_exist(data: dict, expected_keys: list, allow_empty: bool = False, raise_on_fail: bool = True) bool [source]
Validates if expected keys exist (optionally; and has data) in a given dict.
- Parameters:
- Raises:
ValueError – Raised on all validation errors when raise_on_fail = True.
- Returns:
True when validation is passed.
- Return type:
- dict_merge(base: dict, data: dict, path: list | None = None, raise_on_conflict: bool = False) dict [source]
Recursive merge of dict objects into new dict
The merge will make a deep copy of the base dict and merge the data dict into it. It will not modify the base dict being passed in.
If the same key exists in base and data, the value from data will be used unless raise_on_conflict is True, in which case a ValueError will be raised.
- Parameters:
- Raises:
ValueError – Raised on leaf conflict when raise_on_conflict is True
Returns: Merged dict
Filesystem tools
Collection of file helper functions
- find_directory_content(path: str, depth: int = 0, **options: Any) list[dict] [source]
Get directory content and allow os walk. Includes sub levels of user defined depth with metadata and item names as list of dict return.
- Parameters:
- Options:
exclude_files (bool, optional): Exclude files from return. Defaults to False. exclude_directories (bool, optional): Exclude directories from return. Defaults to False. exclude_symlinks (bool, optional): Exclude symlinks from return. Defaults to False. exclude_pattern (str, optional): Pattern to exclude. Defaults to “”. follow_symlinks (bool, optional): Follow symlinks. Defaults to False. order_by (str, optional): Order by key. Defaults to “path”. Not “symlink” or “mount_point” order (str, optional): Order by direction. Defaults to “desc”. “asc”|”desc”
- get_metadata(path: str) dict [source]
Internal function to get filesystem object metadata
- Parameters:
path (str) – Path to fileystem object.
- Returns:
- Filesystem object metadata.
name (str), path (str), size (int) Files only, access time (int or float), crete time (int or float), modify time (int or float), group (int), owner (int), permissions (oct), inode (int), mount_point (bool) directory only, symlink (symlink only), type (str) file|directory|symlink,
- Return type:
- is_directory_readable(path: str) bool [source]
- Checks a directory in a given path to make sure it:
exists
is a directory
is readable
- is_directory_writable(path: str) bool [source]
- Checks a directory in a given path to make sure it:
exists
is a directory
is writable