Allow generation of metrics.json simply by accessing the artifacts folder.
This commit is contained in:
1 parent
7b6c19d8d9
commit
9d7df77923
12 files changed
+802
-486
No files matched your search
@@ -5,17 +5,19 @@ command that demands a database host in order to read a directory is a command n
|
||||
that. What they share is everything after the artifacts are in hand, which is :func:`_report`.
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from cc_common.api import PipelineError, context
|
||||
from cc_common.utils import print
|
||||
from ..vendor.cc_common.api import PipelineError, context
|
||||
from ..vendor.cc_common.utils import print
|
||||
|
||||
# Imported for the properties model; the store half of the tool is the only part that needs it.
|
||||
from persistent_storage.shared import StorageConfiguration
|
||||
from ..vendor.persistent_storage.shared import StorageConfiguration
|
||||
|
||||
from ..metrics import build_metrics
|
||||
from ..rendering import render
|
||||
from ..sources import ReportSources, collect, collect_from_directory
|
||||
|
||||
@@ -105,10 +107,10 @@ def from_folder(properties: FolderProperties) -> GeneratedReport:
|
||||
PipelineError: The folder cannot be read, names no scan, is missing an
|
||||
input the report needs, or the destination cannot be written.
|
||||
"""
|
||||
return _report(collect_from_directory(properties.artifacts, properties.scan_id), properties.path)
|
||||
return _report(collect_from_directory(properties.artifacts, properties.scan_id), properties.path, write_metrics=True)
|
||||
|
||||
|
||||
def _report(sources: ReportSources, path: Path | None) -> GeneratedReport:
|
||||
def _report(sources: ReportSources, path: Path | None, *, write_metrics: bool = False) -> GeneratedReport:
|
||||
"""Render the collected artifacts and write the result.
|
||||
|
||||
Everything after the artifacts are in hand, which is the same whichever of the two collected
|
||||
@@ -130,6 +132,10 @@ def _report(sources: ReportSources, path: Path | None) -> GeneratedReport:
|
||||
try:
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
destination.write_bytes(content)
|
||||
if write_metrics:
|
||||
(destination.parent / "metrics.json").write_text(
|
||||
json.dumps(build_metrics(sources), indent=2), encoding="utf-8"
|
||||
)
|
||||
except OSError as error:
|
||||
message = f"Cannot write the report to '{destination}': {error}"
|
||||
|
||||
|
||||
Reference in new issue
Block a user