Commit d22887a2 authored by Leo Iannacone's avatar Leo Iannacone

wrap JSONLogger in 00_JSONLogger and ZZ_JSONLogger to get module run as first...

wrap JSONLogger in 00_JSONLogger and ZZ_JSONLogger to get module run as first and last one in pre_* and post_* methods
parent 9603deff
...@@ -14,10 +14,10 @@ Some **debomatic-webui** instances are already running over: ...@@ -14,10 +14,10 @@ Some **debomatic-webui** instances are already running over:
## Requirements ## Requirements
You need **JSONLogger** debomatic module (provided along with this interface) to get installed in debomatic. You need **JSONLogger** debomatic module (provided along with this interface) to get installed in debomatic, type this in a command line:
You can copy `debomatic-modules/ZZZ_JSONLogger.py` or link to the modules directory. In the most cases:
``` ```
sudo cp debomatic-modules/ZZZ_JSONLogger.py /usr/share/debomatic/modules/ sudo ln -s `pwd`/debomatic-modules/JSONLogger.py /usr/share/debomatic/modules/00_JSONLogger.py
sudo ln -s `pwd`/debomatic-modules/JSONLogger.py /usr/share/debomatic/modules/ZZ_JSONLogger.py
``` ```
Restart debomatic service. Restart debomatic service.
......
...@@ -31,7 +31,49 @@ from json import load as fileToJSON ...@@ -31,7 +31,49 @@ from json import load as fileToJSON
from collections import defaultdict from collections import defaultdict
class DebomaticModule_ZZZ_JSONLogger: # ZZ and 00 are wrappers for JSONLogger to get module run
# as first and as last one for pre_* and post_* hooks
class DebomaticModule_00_JSONLogger:
def __init__(self):
self.logger = JSONLogger.Instance()
def pre_chroot(self, args):
self.logger.pre_chroot(args)
def pre_build(self, args):
self.logger.pre_build(args)
class DebomaticModule_ZZ_JSONLogger:
def __init__(self):
self.logger = JSONLogger.Instance()
def post_chroot(self, args):
self.logger.post_chroot(args)
def post_build(self, args):
self.logger.post_build(args)
# Singleton decorator
class Singleton:
def __init__(self, decorated):
self._decorated = decorated
def Instance(self):
try:
return self._instance
except AttributeError:
self._instance = self._decorated()
return self._instance
def __call__(self):
raise TypeError('Singletons must be accessed through `Instance()`.')
# The real JSONLogger Class
@Singleton
class JSONLogger:
def __init__(self): def __init__(self):
self.jsonfile = '/var/log/debomatic-json.log' self.jsonfile = '/var/log/debomatic-json.log'
...@@ -128,6 +170,7 @@ class DebomaticModule_ZZZ_JSONLogger: ...@@ -128,6 +170,7 @@ class DebomaticModule_ZZZ_JSONLogger:
self._write_json_logfile(args, status) self._write_json_logfile(args, status)
# Parser for log files
class LogParser(): class LogParser():
def __init__(self, file_path): def __init__(self, file_path):
self.file = file_path self.file = file_path
...@@ -152,7 +195,7 @@ class LogParser(): ...@@ -152,7 +195,7 @@ class LogParser():
for line in fd: for line in fd:
if len(line) >= 2 and line[0] != 'N' and line[1] == ':': if len(line) >= 2 and line[0] != 'N' and line[1] == ':':
tags[line[0]] += 1 tags[line[0]] += 1
return _from_tags_to_result(tags) return self._from_tags_to_result(tags)
def parse_autopkgtest(self): def parse_autopkgtest(self):
tags = defaultdict(int) tags = defaultdict(int)
...@@ -173,7 +216,7 @@ class LogParser(): ...@@ -173,7 +216,7 @@ class LogParser():
tags[info[0]] += 1 tags[info[0]] += 1
elif found and line == '\n': elif found and line == '\n':
break break
return _from_tags_to_result(tags) return self._from_tags_to_result(tags)
def parse_piuparts(self): def parse_piuparts(self):
with open(self.file, 'r') as fd: with open(self.file, 'r') as fd:
...@@ -182,8 +225,7 @@ class LogParser(): ...@@ -182,8 +225,7 @@ class LogParser():
return 'E' return 'E'
return None return None
def _from_tags_to_result(self, tags):
def _from_tags_to_result(tags):
keys = sorted(list(tags.keys())) keys = sorted(list(tags.keys()))
result = [] result = []
for k in keys: for k in keys:
......
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