Skip to content

Commit 813514d

Browse files
committed
sweep: #5737 fix: gzipping in py2 and py3
1 parent d8ca7c2 commit 813514d

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/DIRAC/FrameworkSystem/private/SecurityFileLog.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from __future__ import absolute_import
2-
from __future__ import division
3-
from __future__ import print_function
4-
51
import os
62
import re
73
import time
84
import gzip
95
import queue
6+
import shutil
107
import threading
118
from DIRAC import gLogger, S_OK, S_ERROR
129
from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler
@@ -77,14 +74,9 @@ def __unlinkOldLog(self, filePath):
7774
def __zipOldLog(self, filePath):
7875
try:
7976
gLogger.info("Compressing file %s" % filePath)
80-
fd = gzip.open("%s.gz" % filePath, "w")
81-
with open(filePath) as fO:
82-
bS = 1048576 # 1MiB
83-
buf = fO.read(bS)
84-
while buf:
85-
fd.write(buf)
86-
buf = fO.read(bS)
87-
fd.close()
77+
with open(filePath, "rb") as f_in:
78+
with gzip.open("%s.gz" % filePath, "wb") as f_out:
79+
shutil.copyfileobj(f_in, f_out)
8880
except Exception:
8981
gLogger.exception("Can't compress old log file", filePath)
9082
return 1

0 commit comments

Comments
 (0)