Helpers¶
Utility functions.
Classes:
| Name | Description |
|---|---|
SafeDict |
A helper class for string formatting. |
Functions:
| Name | Description |
|---|---|
calc_unique_path_name |
Calculate a unique path name in the destination. |
strtobool |
Convert a string representation of truth to true (1) or false (0). |
convert_string_to_list |
Convert a comma-separated string to a list. |
convert_byte_to_human_readable_size |
Convert bytes to human readable string. |
remove_directory |
Remove a directory and its contents. |
are_paths_equal |
Compare two paths for equality, accounting for case sensitivity. |
load_json |
Load JSON data from a file and return as a dictionary. |
save_json |
Save a dictionary as JSON data to a file. |
get_stem_and_ext |
Get the stem and extension of a file path. |
get_duration |
Get the duration of a media file. |
SafeDict
¶
Bases: dict
A helper class for string formatting.
If a key is missing, it returns the key wrapped in braces instead of raising a KeyError.
Methods:
| Name | Description |
|---|---|
__missing__ |
Return the key wrapped in braces if missing. |
__missing__(key: str) -> str
¶
Return the key wrapped in braces if missing.
calc_unique_path_name(dest: str, stem_or_name: str, ext: str = '') -> str
¶
Calculate a unique path name in the destination.
strtobool(*, val: str | int | bool) -> bool
¶
Convert a string representation of truth to true (1) or false (0).
Replaces distutils.util.strtobool function (deprecated in Python 3.10).
True values are: y, yes, t, true, on, 1 False values are: n, no, f, false, off, 0
Raises ValueError if val is anything else.
convert_string_to_list(string: str, sep: str = ',') -> tuple[str, ...]
¶
Convert a comma-separated string to a list.
convert_byte_to_human_readable_size(nbytes: int) -> str
¶
Convert bytes to human readable string.
remove_directory(path: str) -> None
¶
Remove a directory and its contents.
are_paths_equal(path1: str, path2: str) -> bool
¶
Compare two paths for equality, accounting for case sensitivity.
load_json(path: str) -> dict[str, Any]
¶
Load JSON data from a file and return as a dictionary.
save_json(path: str, data: dict[str, Any]) -> None
¶
Save a dictionary as JSON data to a file.
get_stem_and_ext(path: str) -> tuple[str, str]
¶
Get the stem and extension of a file path.
get_duration(path: os.PathLike) -> float
¶
Get the duration of a media file.