Coverage for lobster/common/tracing_policy_loader.py: 100%
13 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-13 15:05 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-13 15:05 +0000
1#!/usr/bin/env python3
2#
3# LOBSTER - Lightweight Open BMW Software Traceability Evidence Report
4# Copyright (C) 2026 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/>.
20# Picks the tracing-policy reader based on the config file's extension, then
21# hands the resulting RawPolicy to build_tracing_policy() regardless of
22# which reader produced it.
24from pathlib import Path
25from typing import OrderedDict
27from lobster.common.level_definition import LevelDefinition
28from lobster.common.parser import Parser
29from lobster.common.policy_builder import build_tracing_policy
30from lobster.common.yaml_policy_reader import read_yaml_policy
32YAML_EXTENSIONS = (".yaml", ".yml")
35def load_tracing_policy(
36 mh,
37 filename: str,
38) -> OrderedDict[str, LevelDefinition]:
39 """Load a tracing policy and return its level definitions by name.
41 Returns:
42 An ordered mapping from each level's name to its ``LevelDefinition``.
43 """
44 if Path(filename).suffix.lower() in YAML_EXTENSIONS:
45 raw_policy = read_yaml_policy(filename)
46 else:
47 print(f"{filename}: warning: the tracing-policy in the LOBSTER configuration "
48 "language is deprecated and will be removed in a future "
49 "release. Use a .yaml file instead")
50 raw_policy = Parser(mh, filename).parse()
51 return build_tracing_policy(raw_policy)