Coverage for lobster/tools/core/report/report.py: 44%
32 statements
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-06 09:51 +0000
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-06 09:51 +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
21import sys
23from lobster.exceptions import LOBSTER_Exception
24from lobster.errors import LOBSTER_Error
25from lobster.meta_data_tool_base import MetaDataToolBase
26from lobster.report import Report
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 except FileNotFoundError as e:
54 print(f"{e}")
55 except TypeError as e:
56 print(f"{e}")
57 except LOBSTER_Error as e:
58 raise LOBSTER_Exception(
59 f"{self.name}: aborting due to earlier errors."
60 ) from e
61 except LOBSTER_Exception as err:
62 err.dump()
63 raise
65 report.write_report(options.out)
66 return 0
69def generate_report_file(lobster_config_file: str, output_file: str) -> dict:
70 # This is an API function to run the lobster report tool
71 report = Report()
72 report.parse_config(lobster_config_file)
73 report.write_report(output_file)
76def main() -> int:
77 return ReportTool().run()
80if __name__ == "__main__":
81 sys.exit(main())