timor.utilities.asset_handling

Functions

find_key(key, data[, modifier, search_depth])

Find all appearances of key in a nested dict / sequence combination and return references to each.

handle_assets(new_files, old_files[, ...])

Check if all old_files exist as new_files and resolve missing according to handle_missing_assets.

Module Contents

timor.utilities.asset_handling.find_key(key, data, modifier=None, search_depth=20)

Find all appearances of key in a nested dict / sequence combination and return references to each.

Parameters:
  • key (str) – The key to search for.

  • data (Union[Dict, Sequence]) – The data to search in.

  • modifier (Optional[Callable[[Any], Any]]) – An optional modifier function to apply to each found data.

  • search_depth (int) – The maximum depth to search in.

Returns:

A tuple of lists of all found values with matching key before and after the applied modifier.

Note:

Based on https://stackoverflow.com/questions/9807634/find-all-occurrences-of-a-key-in-nested-dictionaries-and-lists

Return type:

Tuple[List[Any], List[Any]]

timor.utilities.asset_handling.handle_assets(new_files, old_files, handle_missing_assets=DEFAULT_ASSETS_COPY_BEHAVIOR)

Check if all old_files exist as new_files and resolve missing according to handle_missing_assets.

Parameters:
  • new_files (List[pathlib.Path]) – The list of files at the new location.

  • old_files (List[pathlib.Path]) – The list of files at the old location.

  • handle_missing_assets (Optional[str]) – How to handle missing assets at save_at location. * “warning”: Warn if missing. * “error”: Raise FileNotFoundError if missing. * “ignore”: Ignore missing. * “copy”: Copy missing from old to new location. * “symlink”: Symlink missing from old to new location.