42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
|
|
"""
|
||
|
|
Reporter — фасад для всех форматов отчётности.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import logging
|
||
|
|
from typing import List
|
||
|
|
|
||
|
|
from config import AnalyzerConfig, DEFAULT_CONFIG
|
||
|
|
from models import AnalysisReport
|
||
|
|
from reporters.json_reporter import JsonReporter
|
||
|
|
from reporters.html_reporter import HtmlReporter
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
|
||
|
|
class Reporter:
|
||
|
|
"""Управляет формированием отчётов в нескольких форматах."""
|
||
|
|
|
||
|
|
def __init__(self, config: AnalyzerConfig = DEFAULT_CONFIG):
|
||
|
|
self.config = config
|
||
|
|
self._json = JsonReporter()
|
||
|
|
self._html = HtmlReporter()
|
||
|
|
|
||
|
|
def generate(self, report: AnalysisReport) -> List[str]:
|
||
|
|
"""
|
||
|
|
Формирует все отчёты согласно конфигурации.
|
||
|
|
|
||
|
|
:returns: список путей к созданным файлам
|
||
|
|
"""
|
||
|
|
output_dir = self.config.output_dir
|
||
|
|
created: List[str] = []
|
||
|
|
|
||
|
|
if "json" in self.config.output_formats:
|
||
|
|
path = self._json.write(report, output_dir)
|
||
|
|
created.append(path)
|
||
|
|
|
||
|
|
if "html" in self.config.output_formats:
|
||
|
|
path = self._html.write(report, output_dir)
|
||
|
|
created.append(path)
|
||
|
|
|
||
|
|
return created
|