Skip to content

Commit

Permalink
Database: introduce a short name property
Browse files Browse the repository at this point in the history
this is not too useful IMO, but the spec says `index.xml` (contained
by `.pdx` files) should contain a non-empty `SHORT-NAME` tag...

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Michael Hahn <[email protected]>
  • Loading branch information
andlaus committed Sep 9, 2024
1 parent c048d0d commit 2c5396a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
Binary file modified examples/somersault.pdx
Binary file not shown.
Binary file modified examples/somersault_modified.pdx
Binary file not shown.
1 change: 1 addition & 0 deletions examples/somersaultecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,7 @@ class SomersaultSID(IntEnum):

# create a database object
database = Database()
database.short_name = "somersault_database"
database._diag_layer_containers = NamedItemList([somersault_dlc])
database._comparam_subsets = NamedItemList(comparam_subsets)
database._comparam_specs = NamedItemList(comparam_specs)
Expand Down
17 changes: 15 additions & 2 deletions odxtools/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .diaglayers.ecuvariant import EcuVariant
from .diaglayers.functionalgroup import FunctionalGroup
from .diaglayers.protocol import Protocol
from .exceptions import odxraise
from .exceptions import odxraise, odxrequire
from .nameditemlist import NamedItemList
from .odxlink import OdxLinkDatabase, OdxLinkId

Expand All @@ -36,6 +36,7 @@ def __init__(self) -> None:
self._diag_layer_containers = NamedItemList[DiagLayerContainer]()
self._comparam_subsets = NamedItemList[ComparamSubset]()
self._comparam_specs = NamedItemList[ComparamSpec]()
self._short_name = "odx_database"

def add_pdx_file(self, pdx_file: Union[str, "PathLike[Any]", IO[bytes], ZipFile]) -> None:
"""Add PDX file to database.
Expand All @@ -54,7 +55,11 @@ def add_pdx_file(self, pdx_file: Union[str, "PathLike[Any]", IO[bytes], ZipFile]
if p.suffix.lower().startswith(".odx"):
root = ElementTree.parse(pdx_zip.open(zip_member)).getroot()
self._process_xml_tree(root)
elif p.name.lower() != "index.xml":
elif p.name.lower() == "index.xml":
root = ElementTree.parse(pdx_zip.open(zip_member)).getroot()
db_short_name = odxrequire(root.findtext("SHORT-NAME"))
self.short_name = db_short_name
else:
self.add_auxiliary_file(zip_member, pdx_zip.open(zip_member))

def add_odx_file(self, odx_file_name: Union[str, "PathLike[Any]"]) -> None:
Expand Down Expand Up @@ -158,6 +163,14 @@ def odxlinks(self) -> OdxLinkDatabase:
"""A map from odx_id to object"""
return self._odxlinks

@property
def short_name(self) -> str:
return self._short_name

@short_name.setter
def short_name(self, value: str) -> None:
self._short_name = value

@property
def ecu_shared_datas(self) -> NamedItemList[EcuSharedData]:
"""All ECU shared data layers defined by this database
Expand Down
2 changes: 1 addition & 1 deletion odxtools/templates/index.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-#}
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" F-DTD-VERSION="ODX-2.2.0" xsi:noNamespaceSchemaLocation="odx-cc.xsd">
<SHORT-NAME>{{ecu_name}}</SHORT-NAME>
<SHORT-NAME>{{database.short_name}}</SHORT-NAME>
<ABLOCKS>
{%- for file_name, creation_date, mime_type in file_index %}
<ABLOCK UPD="UNCHANGED">
Expand Down

0 comments on commit 2c5396a

Please sign in to comment.