[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [sbws/master] Add function to compress files passed as arg
commit 90d29317d2bcbaa4f61c9063448759d3749c4a00
Author: juga0 <juga@xxxxxxxxxx>
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)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits