datumaro.util.os_util#

Functions

catch_output()

check_instruction_set(instruction)

copytree(src, dst)

dir_items(path, ext[, truncate_ext])

extract_subset_name_from_parent(url, start)

Extract subset name from the given url.

find_files(dirpath, exts[, recursive, ...])

generate_next_name(names, basename[, sep, ...])

Generates the "next" name by appending a next index to the occurrence of the basename with the highest index in the input collection.

get_all_file_extensions(path, ignore_dirs)

import_foreign_module(name, path)

is_subpath(path, base)

Tests if a path is subpath of another path or the paths are equal.

make_file_name(s)

Normalizes string, converts to lowercase, removes non-alpha characters, and converts spaces to hyphens.

split_path(path)

suppress_output([stdout, stderr])

walk(path[, max_depth, min_depth])

datumaro.util.os_util.check_instruction_set(instruction)[source]#
datumaro.util.os_util.import_foreign_module(name, path)[source]#
datumaro.util.os_util.walk(path, max_depth: int | None = None, min_depth: int | None = None)[source]#
datumaro.util.os_util.find_files(dirpath: str, exts: str | Iterable[str], recursive: bool = False, max_depth: int | None = None, min_depth: int | None = None) Iterator[str][source]#
datumaro.util.os_util.copytree(src, dst)[source]#
datumaro.util.os_util.suppress_output(stdout: bool = True, stderr: bool = False)[source]#
datumaro.util.os_util.catch_output()[source]#
datumaro.util.os_util.dir_items(path, ext, truncate_ext=False)[source]#
datumaro.util.os_util.split_path(path)[source]#
datumaro.util.os_util.is_subpath(path: str, base: str) bool[source]#

Tests if a path is subpath of another path or the paths are equal.

datumaro.util.os_util.make_file_name(s: str) str[source]#

Normalizes string, converts to lowercase, removes non-alpha characters, and converts spaces to hyphens.

datumaro.util.os_util.generate_next_name(names: Iterable[str], basename: str, sep: str = '.', suffix: str = '', default: str | None = None) str[source]#

Generates the “next” name by appending a next index to the occurrence of the basename with the highest index in the input collection.

Returns: next string name

Example:

Inputs:

name_abc

name_base

name_base1

name_base5

Basename: name_base

Output: name_base6

datumaro.util.os_util.extract_subset_name_from_parent(url: str, start: str) str[source]#

Extract subset name from the given url.

For example, if url = “/a/b/images/train/img.jpg” and start = “/a/b”, it will return “train”. On the other hand, if url = “/a/b/images/img.jpg” and start = “/a/b”, it will return DEFAULT_SUBSET_NAME.

Parameters:
  • url (str) – Given url to extract subset

  • start – The head path of url to obtain the relative path from the url

Returns:

Subset name

Return type:

str

datumaro.util.os_util.get_all_file_extensions(path: str, ignore_dirs: Set[str]) List[str][source]#