diff --git a/tools/python/jwutils/misc.py b/tools/python/jwutils/misc.py index 94997c1..108f428 100644 --- a/tools/python/jwutils/misc.py +++ b/tools/python/jwutils/misc.py @@ -4,7 +4,7 @@ import tempfile import filecmp import inspect import importlib -from typing import Set +from typing import Set, Iterable from jwutils import log _tmpfiles: Set[str] = set() @@ -108,4 +108,16 @@ def commit_tmpfile(tmp: str, path: str) -> None: # export log.slog(log.NOTICE, "saving {}".format(path), caller=caller) os.rename(path + '.tmp', path) +def dump(prio: int, objects: Iterable, *args, **kwargs) -> None: # export + caller = log.get_caller_pos(kwargs=kwargs) + log.slog(prio, ",---------- {}".format(' '.join(args)), caller=caller) + prefix = " | " + log.append_to_prefix(prefix) + i = 1 + for o in objects: + o.dump(prio, "{} ({})".format(i, o.__class__.__name__), caller=caller, **kwargs) + i += 1 + log.remove_from_prefix(prefix) + log.slog(prio, "`---------- {}".format(' '.join(args)), caller=caller) + atexit.register(_cleanup)