Skip to content

Commit

Permalink
some fixes for files using ODX 2.0
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Florian Jost <[email protected]>
  • Loading branch information
andlaus committed May 7, 2024
1 parent 7bdf4f8 commit 30dbdac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion odxtools/diaglayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions odxtools/diaglayerraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 30dbdac

Please sign in to comment.