Commit 27afaa51 authored by Leo Iannacone's avatar Leo Iannacone

parse log files in post_build hooks

parent 70395d9a
......@@ -28,6 +28,7 @@ import os
from time import time
from json import dumps as toJSON
from json import load as fileToJSON
from collections import defaultdict
class DebomaticModule_JSONLogger:
......@@ -113,10 +114,80 @@ class DebomaticModule_JSONLogger:
status = self._get_package_status(args)
status['status'] = 'build'
status['success'] = False
status['tags'] = {}
resultdir = os.path.join(args['directory'], 'pool', args['package'])
for filename in os.listdir(resultdir):
if filename.endswith('.dsc'):
status['success'] = True
break
else:
full_path = os.path.join(resultdir, filename)
tag = LogParser(full_path).parse()
if tag:
status['tags'][filename] = tag
self._write_package_json(args, status)
self._write_json_logfile(args, status)
class LogParser():
def __init__(self, file_path):
self.file = file_path
self.basename = os.path.basename(file_path)
self.extension = self.basename.split('.').pop()
def parse(self):
if not os.path.isfile(self.file):
return None
result = None
if self.extension == 'lintian':
result = self.parse_lintian()
elif self.extension == 'autopkgtest':
result = self.parse_autopkgtest()
elif self.extension == 'piuparts':
result = self.parse_piuparts()
return result
def parse_lintian(self):
tags = defaultdict(int)
with open(self.file, 'r') as fd:
for line in fd:
if len(line) >= 2 and line[0] != 'N' and line[1] == ':':
tags[line[0]] += 1
return _from_tags_to_result(tags)
def parse_autopkgtest(self):
tags = defaultdict(int)
with open(self.file, 'r') as fd:
found = False
pass_next = False
for line in fd:
if pass_next:
pass_next = False
continue
if not found and line.find('Tests summary') >= 0:
found = True
pass_next = True
elif found and len(line.split()) >= 2:
info = line.split()[1]
if info == 'PASS':
continue
tags[info[0]] += 1
elif found and line == '\n':
break
return _from_tags_to_result(tags)
def parse_piuparts(self):
with open(self.file, 'r') as fd:
last_line = fd.readlines()[-1]
if last_line.find('ERROR:') >= 0:
return 'E'
return None
def _from_tags_to_result(tags):
keys = sorted(list(tags.keys()))
result = []
for k in keys:
result.append("%s%s" % (k, tags[k]))
if len(result) > 0:
return ' '.join(result)
return None
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment