Skip to content

Commit

Permalink
Merge pull request #262 from andlaus/fix_docref_in_parent-ref
Browse files Browse the repository at this point in the history
use the correct value for the DOCREF in PARENT-REFs
  • Loading branch information
andlaus authored Feb 1, 2024
2 parents a00a441 + 9109dfa commit f34c3fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion odxtools/templates/macros/printParentRef.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{%- macro printParentRef(par) -%}
<PARENT-REF ID-REF="{{par.layer.odx_id.local_id}}"
DOCREF="{{par.layer.short_name}}"
DOCREF="{{get_parent_container_name(par.layer.short_name)}}"
DOCTYPE="CONTAINER"
xsi:type="{{par.layer.variant_type.value}}-REF">
{%- if par.not_inherited_diag_comms %}
Expand Down
21 changes: 20 additions & 1 deletion odxtools/write_pdx_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -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__
Expand Down

0 comments on commit f34c3fc

Please sign in to comment.