From 9109dfa6b4d8be2f839e1acc414314708689a101 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Thu, 1 Feb 2024 11:12:35 +0100 Subject: [PATCH] use the correct value for the DOCREF in PARENT-REFs this is supposed to be the short name of the container which contains the referenced layer, not the short name of the layer itself. Signed-off-by: Andreas Lauser Signed-off-by: Alexander Walz --- .../macros/printParentRef.xml.jinja2 | 2 +- odxtools/write_pdx_file.py | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/odxtools/templates/macros/printParentRef.xml.jinja2 b/odxtools/templates/macros/printParentRef.xml.jinja2 index da859b6e..0385d2dc 100644 --- a/odxtools/templates/macros/printParentRef.xml.jinja2 +++ b/odxtools/templates/macros/printParentRef.xml.jinja2 @@ -5,7 +5,7 @@ {%- macro printParentRef(par) -%} {%- if par.not_inherited_diag_comms %} diff --git a/odxtools/write_pdx_file.py b/odxtools/write_pdx_file.py index ae3e6554..2e7b9eed 100644 --- a/odxtools/write_pdx_file.py +++ b/odxtools/write_pdx_file.py @@ -13,13 +13,31 @@ from .database import Database from .odxtypes import bool_to_odxstr -odxdatabase = None +odxdatabase: Optional[Database] = None def jinja2_odxraise_helper(msg: str) -> None: raise Exception(msg) +def get_parent_container_name(dl_short_name: str) -> str: + """ + Given the short name of a diagnostic layer, return the name of a container + which the layer is part of. + + If no such container exists, a `RuntimeException` is thrown. + """ + + assert odxdatabase is not None + + for dlc in odxdatabase.diag_layer_containers: + if dl_short_name in [dl.short_name for dl in dlc.diag_layers]: + return dlc.short_name + + raise RuntimeError(f"get_parent_container_name() could not determine a " + f"container for diagnostic layer '{dl_short_name}'.") + + def make_xml_attrib(attrib_name: str, attrib_val: Optional[Any]) -> str: if attrib_val is None: return "" @@ -117,6 +135,7 @@ def write_pdx_file( jinja_env.globals["odxraise"] = jinja2_odxraise_helper jinja_env.globals["make_xml_attrib"] = make_xml_attrib jinja_env.globals["make_bool_xml_attrib"] = make_bool_xml_attrib + jinja_env.globals["get_parent_container_name"] = get_parent_container_name vars: Dict[str, Any] = {} vars["odxtools_version"] = odxtools.__version__