From: Michael Tremer Date: Wed, 19 Oct 2022 13:41:47 +0000 (+0000) Subject: jobs: Compress log files X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=703b2fda747d6a3b9796fea9e1402d39ff159a23;p=pbs.git jobs: Compress log files Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 7c210830..c1c73415 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -2,6 +2,7 @@ import asyncio import datetime +import gzip import hashlib import logging import os @@ -382,11 +383,12 @@ class Job(base.DataObject): "jobs", self.uuid[0:2], self.uuid[2:4], - "%s.log" % self.uuid[4:], + "%s.log.gz" % self.uuid[4:], ) - # Copy file to its destination - await self.backend.copy(upload.path, path) + # Open the destination path + with gzip.open(path, "wb", compresslevel=9) as f: + await upload.copyinto(f) # Compute a digest for integrity digest = await upload.digest("blake2s") diff --git a/src/buildservice/uploads.py b/src/buildservice/uploads.py index cc926cd4..41c4b9dc 100644 --- a/src/buildservice/uploads.py +++ b/src/buildservice/uploads.py @@ -312,3 +312,14 @@ class Upload(base.DataObject): # Return the digest return h.digest() + + async def copyinto(self, dst): + """ + Copies the content of this upload into the destination file descriptor. + """ + return await asyncio.to_thread(self._copyinfo, dst) + + def _copyinto(self, dst): + # Open the source file and copy it into the destination file descriptor + with open(self.path, "rb") as src: + shutil.copyfileobj(src, dst)