Coverage for lobster/tools/core/report/report.py: 90%
31 statements
« prev ^ index » next coverage.py v7.10.5, created at 2025-08-27 13:02 +0000
« prev ^ index » next coverage.py v7.10.5, created at 2025-08-27 13:02 +0000
1#!/usr/bin/env python3
2#
3# LOBSTER - Lightweight Open BMW Software Traceability Evidence Report
4# Copyright (C) 2023-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as
8# published by the Free Software Foundation, either version 3 of the
9# License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public
17# License along with this program. If not, see
18# <https://www.gnu.org/licenses/>.
20from argparse import Namespace
21from typing import Optional, Sequence
23from lobster.common.exceptions import LOBSTER_Exception
24from lobster.common.errors import LOBSTER_Error
25from lobster.common.report import Report
26from lobster.common.meta_data_tool_base import MetaDataToolBase
29class ReportTool(MetaDataToolBase):
30 def __init__(self):
31 super().__init__(
32 name="lobster-report",
33 description="Generate a LOBSTER report from a lobster.conf file",
34 official=True,
35 )
36 self._argument_parser.add_argument(
37 "--lobster-config",
38 metavar="FILE",
39 default="lobster.conf",
40 )
41 self._argument_parser.add_argument(
42 "--out",
43 metavar="FILE",
44 default="report.lobster",
45 )
47 def _run_impl(self, options: Namespace) -> int:
49 report = Report()
51 try:
52 report.parse_config(options.lobster_config)
53 report.write_report(options.out)
54 return 0
55 except FileNotFoundError as e:
56 print(e)
57 except LOBSTER_Error as e:
58 print(e)
59 print(f"{self.name}: aborting due to earlier errors.")
60 except LOBSTER_Exception as err:
61 err.dump()
63 return 1
66def generate_report_file(lobster_config_file: str, output_file: str) -> dict:
67 # This is an API function to run the lobster report tool
68 report = Report()
69 report.parse_config(lobster_config_file)
70 report.write_report(output_file)
73def main(args: Optional[Sequence[str]] = None) -> int:
74 return ReportTool().run(args)