summaryrefslogtreecommitdiff
path: root/mdbp/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'mdbp/common.py')
-rw-r--r--mdbp/common.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/mdbp/common.py b/mdbp/common.py
index 5c67f58..e4f4792 100644
--- a/mdbp/common.py
+++ b/mdbp/common.py
@@ -198,6 +198,14 @@ def clean_dir(directory: pathlib.Path, patterns: typing.List[str]) -> None:
for pattern in patterns):
entry.unlink()
+@contextlib.contextmanager
+def temporary_static_file(content: str) -> typing.Iterator[pathlib.Path]:
+ """Create a named temporary file with given content and return its path."""
+ with tempfile.NamedTemporaryFile("w") as tmpf:
+ tmpf.write(content)
+ tmpf.flush()
+ yield pathlib.Path(tmpf.name)
+
class AddSpaceSeparatedValues(argparse.Action):
"""The action extends the destination array with the space-sparated parts
of the passed value."""