Coverage for lobster/tools/core/ci_report/ci_report.py: 0%

27 statements  

« prev     ^ index     » next       coverage.py v7.10.5, created at 2025-08-27 13:02 +0000

1#!/usr/bin/env python3 

2# 

3# lobster_ci_report - Visualise LOBSTER issues for CI 

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/>. 

19 

20from argparse import Namespace 

21import os.path 

22from typing import Optional, Sequence 

23 

24from lobster.common.report import Report 

25from lobster.common.items import Tracing_Status 

26from lobster.common.meta_data_tool_base import MetaDataToolBase 

27 

28 

29class CiReportTool(MetaDataToolBase): 

30 def __init__(self): 

31 super().__init__( 

32 name="lobster-ci-report", 

33 description="Command line tool to check a LOBSTER report", 

34 official=True, 

35 ) 

36 

37 self._argument_parser.add_argument( 

38 "lobster_report", 

39 nargs="?", 

40 default="report.lobster", 

41 ) 

42 

43 def _run_impl(self, options: Namespace) -> int: 

44 if not os.path.isfile(options.lobster_report): 

45 if options.lobster_report == "report.lobster": 

46 self._argument_parser.error("specify report file") 

47 else: 

48 self._argument_parser.error(f"{options.lobster_report} is not a file") 

49 

50 report = Report() 

51 report.load_report(options.lobster_report) 

52 

53 for uid in sorted(report.items): 

54 item = report.items[uid] 

55 if item.tracing_status not in (Tracing_Status.OK, 

56 Tracing_Status.JUSTIFIED): 

57 for message in item.messages: 

58 report.mh.error(item.location, 

59 message, 

60 fatal = False) 

61 

62 if report.mh.errors: 

63 return 1 

64 else: 

65 return 0 

66 

67 

68def main(args: Optional[Sequence[str]] = None) -> int: 

69 return CiReportTool().run(args)