foxes.utils.data_book.DataBook

class foxes.utils.data_book.DataBook[source]

Bases: object

Container class for file paths, either directly given or as static data within a package.

Parameters:

data_book (DataBook, optional) – A data book to start from

dbase

The data base. Key: context str, value: dict (file name str to pathlib.Path)

Type:

dict

__init__(data_book=None)[source]

Methods

__init__([data_book])

add_data_package(context, package, file_sfx)

Add static files from a package location.

add_data_package_file(context, package, ...)

Add a static file from a package location.

add_file(context, file_path)

Add a file path

add_files(context, file_paths)

Add file paths

get_file_path(context, file_name[, ...])

Get path of a file

toc(context)

Get list of contents

__init__(data_book=None)[source]
add_data_package(context, package, file_sfx)[source]

Add static files from a package location.

Parameters:
  • context (str) – The context

  • package (str or package) – The package, must contain init file

  • file_sfx (list of str) – File endings to include

add_data_package_file(context, package, file_name)[source]

Add a static file from a package location.

Parameters:
  • context (str) – The context

  • package (str or package) – The package, must contain init.py` file

  • file_mane (str) – The file name

add_file(context, file_path)[source]

Add a file path

Parameters:
  • context (str) – The context

  • file_path (str) – The file path

add_files(context, file_paths)[source]

Add file paths

Parameters:
  • context (str) – The context

  • file_paths (list of str) – The file paths

get_file_path(context, file_name, check_raw=True, errors=True)[source]

Get path of a file

Parameters:
  • context (str) – The context

  • file_name (str) – The file name

  • check_raw (bool) – Check if file_name exists as given, and in that case return the path

  • errors (bool) – Flag for raising KeyError, otherwise return None, if context of file_name not found

Returns:

path – The path

Return type:

pathlib.Path

toc(context)[source]

Get list of contents

Parameters:

context (str) – The context

Returns:

keys – The data keys

Return type:

list of str