mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-08 07:43:20 +08:00
Fix #576: Remove empty/useless log files
This commit is contained in:
@@ -28,6 +28,7 @@ import koji
|
||||
import kobo.rpmlib
|
||||
import modulemd
|
||||
import pipes
|
||||
import re
|
||||
import threading
|
||||
|
||||
from module_build_service import conf, log
|
||||
@@ -324,6 +325,25 @@ mdpolicy=group:primary
|
||||
if os.path.exists(old_log):
|
||||
os.rename(old_log, new_log)
|
||||
|
||||
def _purge_useless_logs(self):
|
||||
"""
|
||||
Remove empty or otherwise useless log files
|
||||
"""
|
||||
for logf in os.listdir(self.resultsdir):
|
||||
|
||||
log_path = os.path.join(self.resultsdir, logf)
|
||||
|
||||
# Remove empty files
|
||||
if os.path.isfile(log_path) and os.path.getsize(log_path) == 0:
|
||||
os.remove(log_path)
|
||||
|
||||
# Remove other files containing useless information
|
||||
elif logf.endswith('-srpm-stdout.log'):
|
||||
with open(log_path) as f:
|
||||
data = f.read(4096)
|
||||
if re.match("Downloading [^\n]*\n\n\nWrote: [^\n]", data):
|
||||
os.remove(log_path)
|
||||
|
||||
def build_srpm(self, artifact_name, source, build_id, builder):
|
||||
"""
|
||||
Builds the artifact from the SRPM.
|
||||
@@ -386,6 +406,10 @@ mdpolicy=group:primary
|
||||
for name in os.listdir(resultsdir):
|
||||
os.rename(os.path.join(resultsdir, name), os.path.join(self.resultsdir, name))
|
||||
|
||||
# Depending on the configuration settings, remove/keep useless log files
|
||||
if conf.mock_purge_useless_logs:
|
||||
self._purge_useless_logs()
|
||||
|
||||
# We return BUILDING state here even when we know it is already
|
||||
# completed or failed, because otherwise utils.start_build_batch
|
||||
# would think this component is already built and also tagged, but
|
||||
|
||||
@@ -322,6 +322,10 @@ class Config(object):
|
||||
'type': Path,
|
||||
'default': '~/modulebuild/builds',
|
||||
'desc': 'Directory for Mock build results.'},
|
||||
'mock_purge_useless_logs': {
|
||||
'type': bool,
|
||||
'default': True,
|
||||
'desc': 'Remove empty or otherwise useless log files.'},
|
||||
'scmurls': {
|
||||
'type': list,
|
||||
'default': [],
|
||||
|
||||
Reference in New Issue
Block a user