commit 25f3fa9ccf3ad5d83cfd36ebf4f0e31b0cd191f6 Author: juga0 juga@riseup.net Date: Tue Jul 17 17:08:50 2018 +0000
Add function to delete files passed as arg --- sbws/core/cleanup.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/sbws/core/cleanup.py b/sbws/core/cleanup.py index bd3300c..3deca57 100644 --- a/sbws/core/cleanup.py +++ b/sbws/core/cleanup.py @@ -1,3 +1,6 @@ +"""Util functions to cleanup disk space.""" +import types + from sbws.util.filelock import DirectoryLock from sbws.globals import (fail_hard, is_initted) from sbws.util.timestamp import unixts_to_dt_obj @@ -93,6 +96,17 @@ def _get_older_files_than(dname, num_days_ago, extensions): yield fname
+def _delete_files(dname, files, dry_run=True): + """Delete the files passed as argument.""" + assert os.path.isdir(dname) + assert isinstance(files, types.GeneratorType) + with DirectoryLock(dname): + for fname in files: + log.info('Deleting %s', fname) + if not dry_run: + os.remove(fname) + + def _remove_rotten_files(datadir, rotten_days, dry_run=True): assert os.path.isdir(datadir) assert isinstance(rotten_days, int)
tor-commits@lists.torproject.org