Source code for thoth.adviser.dm_report

#!/usr/bin/env python3
# thoth-adviser
# Copyright(C) 2018 - 2021 Fridolin Pokorny
# This program is free software: you can redistribute it and / or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <>.

"""Routines for dependency monkey and its output handling."""

import logging
from typing import Any
from typing import Dict
from typing import List
from typing import Union

import attr

from .product import Product

_LOGGER = logging.getLogger(__name__)

[docs]@attr.s(slots=True) class DependencyMonkeyReport: """Report produced by a Dependency Monkey run.""" skipped = attr.ib(type=int, default=0) _responses = attr.ib(type=List[Dict[str, Union[Dict[str, Any], str]]], default=attr.Factory(list))
[docs] def add_response(self, response: str, product: Product) -> None: """Add a new response to response listing.""" self._responses.append({"response": response, "product": product.to_dict()})
[docs] def to_dict(self, *, verbose: bool = False) -> Dict[str, Any]: """Convert report to a dict representation suitable for serialization.""" return {"skipped": self.skipped, "responses": self._responses}