From 30dbdaccf339bf22056f5e588ae75d801a3f1d5e Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Tue, 7 May 2024 14:33:10 +0200 Subject: [PATCH] some fixes for files using ODX 2.0 In ODX 2.0, the `ComparamSpec` does not exist, so `Database.comparam_spec` returns a `ComparamSubset` object. this commit takes care of that and thus hopefully fixes #301. Signed-off-by: Andreas Lauser Signed-off-by: Florian Jost --- odxtools/diaglayer.py | 3 ++- odxtools/diaglayerraw.py | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/odxtools/diaglayer.py b/odxtools/diaglayer.py index a5fc3e37..ff26abb7 100644 --- a/odxtools/diaglayer.py +++ b/odxtools/diaglayer.py @@ -15,6 +15,7 @@ from .companydata import CompanyData from .comparaminstance import ComparamInstance from .comparamspec import ComparamSpec +from .comparamsubset import ComparamSubset from .diagcomm import DiagComm from .diagdatadictionaryspec import DiagDataDictionarySpec from .diaglayerraw import DiagLayerRaw @@ -356,7 +357,7 @@ def prot_stack_snref(self) -> Optional[str]: return self.diag_layer_raw.prot_stack_snref @property - def comparam_spec(self) -> Optional[ComparamSpec]: + def comparam_spec(self) -> Optional[Union[ComparamSpec, ComparamSubset]]: return self.diag_layer_raw.comparam_spec @property diff --git a/odxtools/diaglayerraw.py b/odxtools/diaglayerraw.py index cdc5dca7..eb53c3fa 100644 --- a/odxtools/diaglayerraw.py +++ b/odxtools/diaglayerraw.py @@ -9,6 +9,7 @@ from .companydata import CompanyData from .comparaminstance import ComparamInstance from .comparamspec import ComparamSpec +from .comparamsubset import ComparamSubset from .createsdgs import create_sdgs_from_et from .diagcomm import DiagComm from .diagdatadictionaryspec import DiagDataDictionarySpec @@ -243,7 +244,10 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None: """Recursively resolve all references.""" if self.comparam_spec_ref is not None: - self._comparam_spec = odxlinks.resolve(self.comparam_spec_ref, ComparamSpec) + spec = odxlinks.resolve(self.comparam_spec_ref) + if not isinstance(spec, (ComparamSubset, ComparamSpec)): + odxraise(f"Type {type(spec).__name__} is not allowed for comparam specs") + self._comparam_spec = spec # do ODXLINK reference resolution if self.admin_data is not None: @@ -281,8 +285,10 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None: def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None: self._prot_stack: Optional[ProtStack] = None if self.prot_stack_snref is not None: - self._prot_stack = resolve_snref(self.prot_stack_snref, - odxrequire(self.comparam_spec).prot_stacks, ProtStack) + cp_spec = self.comparam_spec + if isinstance(cp_spec, ComparamSpec): + self._prot_stack = resolve_snref(self.prot_stack_snref, cp_spec.prot_stacks, + ProtStack) # do short-name reference resolution if self.admin_data is not None: @@ -318,7 +324,7 @@ def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None: comparam._resolve_snrefs(diag_layer) @property - def comparam_spec(self) -> Optional[ComparamSpec]: + def comparam_spec(self) -> Optional[Union[ComparamSpec, ComparamSubset]]: return self._comparam_spec @property