From 69fdfcdda423b55c7251e4d46e82563cda98a63d Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 27 May 2021 11:54:04 +0200 Subject: add new field .output.artifacts to schema Using the field you can specify an ORed set of positive glob-style patterns for artifacts to retain in the .output.directory. It defaults to including all artifacts. --- mdbp/common.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'mdbp/common.py') diff --git a/mdbp/common.py b/mdbp/common.py index ba4b20d..df434cb 100644 --- a/mdbp/common.py +++ b/mdbp/common.py @@ -4,6 +4,7 @@ from __future__ import annotations import argparse import contextlib +import fnmatch import hashlib import importlib.resources import json @@ -181,3 +182,12 @@ def tar_add(tarobj: tarfile.TarFile, path: pathlib.Path) -> None: info.mtime = int(statres.st_mtime) with path.open("rb") as fobj: tarobj.addfile(info, fobj) + + +def clean_dir(directory: pathlib.Path, patterns: typing.List[str]) -> None: + """Delete all entries of `directory` that match none of the given + `patterns`.""" + for entry in directory.iterdir(): + if not any(fnmatch.fnmatchcase(entry.name, pattern) + for pattern in patterns): + entry.unlink() -- cgit v1.2.3