cobra_db.utils

Module Contents

Functions

find_files(path, query[, regex])

Lazyly use the "find" bash command to recursively get all the files

find_dcm(path)

Lazy iterator to recursively find all files with .dcm extension under a path

list_dirs(→ List[str])

List all directories directly below path

list_files(→ List[str])

List paths of files with <extension> directly inside a folder.

parse_DA_TM_as_datetime(→ datetime.datetime)

Parse DA and TM as datetime

parse_AS_as_int(→ int)

Parse AS as int

parse_DA_as_datetime(DA)

intersect_dicts(→ dict)

Reads the fist level keys and returns everything that is the same for all dicts.

intersect_dicts_allow_empty_minority(→ dict)

Reads first level keys and returns a dict with all the keys where the values are

cobra_db.utils.find_files(path: str, query: str, regex: bool = False)[source]

Lazyly use the “find” bash command to recursively get all the files that match query on path.

Parameters:
  • path – path to search

  • query – query to match

  • regex – use -regex instead of -name

Raises:

FileNotFoundError – when nothing is found

Yield:

absolute paths of files

cobra_db.utils.find_dcm(path)[source]

Lazy iterator to recursively find all files with .dcm extension under a path

Parameters:

path – path to find

Yield:

absolute paths of files

cobra_db.utils.list_dirs(path: str) List[str][source]

List all directories directly below path

Parameters:

path – path to get directories from

Returns:

list of directories as absolute paths

cobra_db.utils.list_files(folder_path: str, extension: str) List[str][source]

List paths of files with <extension> directly inside a folder.

Parameters:
  • folder_path – the path to the folder

  • extension – the extension to look for

Returns:

list of absolute paths of files

cobra_db.utils.parse_DA_TM_as_datetime(DA: str, TM: str) datetime.datetime[source]

Parse DA and TM as datetime

cobra_db.utils.parse_AS_as_int(AS: str) int[source]

Parse AS as int

cobra_db.utils.parse_DA_as_datetime(DA: str)[source]
cobra_db.utils.intersect_dicts(dicts: List[dict]) dict[source]

Reads the fist level keys and returns everything that is the same for all dicts.

cobra_db.utils.intersect_dicts_allow_empty_minority(dicts: List[dict]) dict[source]

Reads first level keys and returns a dict with all the keys where the values are equal. If the key does not exist in less than half, but all the other dicts that contain it agree on the value, then the key is kept.