mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
misc: Add dump()
Add misc.dump(), which takes an iterable, assumes all elements have a dump() method, and calls it on all of them. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
4a047ca260
commit
c63d1a729e
1 changed files with 13 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue