opsward.util

Shared helpers for opsward.

opsward.util.iter_files(directory: Path, *, suffix: str = '')[source]

Yield files in directory (non-recursive), optionally filtered by suffix.

opsward.util.iter_subdirs(directory: Path)[source]

Yield immediate subdirectories of directory, sorted by name.

opsward.util.read_json_safe(path: Path) dict | None[source]

Read a JSON file, returning None on any failure.

opsward.util.read_text_safe(path: Path) str[source]

Read a text file, returning ‘’ if it doesn’t exist or can’t be decoded.

>>> from pathlib import Path
>>> read_text_safe(Path('/nonexistent/file.txt'))
''