[tor-commits] [sbws/master] Add function to compress files passed as arg

pastly at torproject.org pastly at torproject.org
Thu Aug 9 14:21:19 UTC 2018


commit 90d29317d2bcbaa4f61c9063448759d3749c4a00
Author: juga0 <juga at riseup.net>
Date:   Tue Jul 17 17:09:09 2018 +0000

    Add function to compress files passed as arg
---
 sbws/core/cleanup.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/sbws/core/cleanup.py b/sbws/core/cleanup.py
index 3deca57..d726a23 100644
--- a/sbws/core/cleanup.py
+++ b/sbws/core/cleanup.py
@@ -121,6 +121,22 @@ def _remove_rotten_files(datadir, rotten_days, dry_run=True):
                 os.remove(fname)
 
 
+def _compress_files(dname, files, dry_run=True):
+    """Compress the files passed as argument."""
+    assert os.path.isdir(dname)
+    assert isinstance(files, types.GeneratorType)
+    with DirectoryLock(dname):
+        for fname in files:
+            log.info('Compressing %s', fname)
+            if dry_run:
+                continue
+            with open(fname, 'rt') as in_fd:
+                out_fname = fname + '.gz'
+                with gzip.open(out_fname, 'wt') as out_fd:
+                    shutil.copyfileobj(in_fd, out_fd)
+            os.remove(fname)
+
+
 def _compress_stale_files(datadir, stale_days, dry_run=True):
     assert os.path.isdir(datadir)
     assert isinstance(stale_days, int)





More information about the tor-commits mailing list