odsbox.model_cache¶
helps working with the ASAM ODS model
Classes¶
The ods.Model object returned from ods server needs some utilities to work with it. |
Module Contents¶
- class odsbox.model_cache.ModelCache(model)[source]¶
The ods.Model object returned from ods server needs some utilities to work with it. This cache functionality useful for daily work.
- Parameters:
model (odsbox.proto.ods_pb2.Model)
- model()[source]¶
Get the attached ASAM ODS model.
- Returns:
The used model.
- Return type:
odsbox.proto.ods_pb2.Model
- aid(entity_or_name)[source]¶
Determine the application element id of an entity by its name.
- Parameters:
entity_or_name (str | odsbox.proto.ods_pb2.Model.Entity) – Entity object or case sensitive application name to lookup.
- Returns:
The ApplicationElementId of the entity.
- Raises:
ValueError – If the entity does not exist.
- Return type:
int
- entity(entity_name)[source]¶
Get the entity by name. If no application name matches, it will try to match the base name.
- Parameters:
entity_name (str) – Case insensitive name of an entity.
- Returns:
The found entity.
- Raises:
ValueError – If the entity does not exist.
- Return type:
odsbox.proto.ods_pb2.Model.Entity
- entity_no_throw(entity_name)[source]¶
Get the entity by name. Returns None if not found. if no application name matches, it will try to match the base name.
- Parameters:
entity_name (str) – Case insensitive name of an entity or base name.
- Returns:
The found entity or None.
- Return type:
odsbox.proto.ods_pb2.Model.Entity | None
- entity_by_base_name(entity_base_name)[source]¶
Get the entity by its base name.
- Parameters:
entity_base_name (str) – Case insensitive name of the base model element.
- Raises:
ValueError – If the entity does not exist.
- Return type:
odsbox.proto.ods_pb2.Model.Entity
- entity_by_aid(aid)[source]¶
Get the entity by its ApplicationElementId(aid).
- Parameters:
aid (int) – ApplicationElementId of an entity to lookup.
- Returns:
Entity corresponding to given aid.
- Raises:
ValueError – If the entity does not exist.
- Return type:
odsbox.proto.ods_pb2.Model.Entity
- attribute_no_throw(entity_or_name, application_or_base_name)[source]¶
This is a convenience method to find an attribute. It will first check for an attribute with the given application name and afterwards check for an attribute with the given base name.
- Parameters:
entity_or_name (str | odsbox.proto.ods_pb2.Model.Entity) – Entity or case insensitive name of an entity.
application_or_base_name (str) – Case insensitive name to lookup.
- Returns:
The found attribute or None.
- Raises:
ValueError – If entity does not exist.
- Return type:
odsbox.proto.ods_pb2.Model.Attribute | None
- attribute(entity_or_name, application_or_base_name)[source]¶
This is a convenience method to find an attribute. It will first check for an attribute with the given application name and afterwards check for an attribute with the given base name.
- Parameters:
entity_or_name (str | odsbox.proto.ods_pb2.Model.Entity) – Entity or case insensitive name of an entity.
application_or_base_name (str) – Case insensitive name to lookup.
- Returns:
The found attribute.
- Raises:
ValueError – If attribute does not exist.
- Return type:
odsbox.proto.ods_pb2.Model.Attribute
- attribute_by_base_name(entity_or_name, attribute_base_name)[source]¶
Get the attribute by base name.
- Parameters:
entity_or_name (str | odsbox.proto.ods_pb2.Model.Entity) – Entity object or case sensitive application name to lookup.
attribute_base_name (str) – Case insensitive name of the base model element.
- Returns:
Corresponding attribute.
- Raises:
ValueError – If the attribute does not exist.
- Return type:
odsbox.proto.ods_pb2.Model.Attribute
- relation_no_throw(entity_or_name, application_or_base_name)[source]¶
This is a convenience method to find a relation. It will first check for a relation with the given application name and afterwards check for a relation with the given base name.
- Parameters:
entity_or_name (str | odsbox.proto.ods_pb2.Model.Entity) – Entity or case insensitive name of an entity.
application_or_base_name (str) – Case insensitive name to lookup.
- Returns:
The relation or None if it does not exist.
- Raises:
ValueError – If entity does not exist.
- Return type:
odsbox.proto.ods_pb2.Model.Relation | None
- relation(entity_or_name, application_or_base_name)[source]¶
This is a convenience method to find a relation. It will first check for a relation with the given application name and afterwards check for a relation with the given base name.
- Parameters:
entity_or_name (str | odsbox.proto.ods_pb2.Model.Entity) – Entity or case insensitive name of an entity.
application_or_base_name (str) – Case insensitive name to lookup.
- Returns:
The found relation.
- Raises:
ValueError – If relation does not exist.
- Return type:
odsbox.proto.ods_pb2.Model.Relation
- relation_by_base_name(entity_or_name, relation_base_name)[source]¶
Get the relation by base name.
- Parameters:
entity_or_name (str | odsbox.proto.ods_pb2.Model.Entity) – Entity object or case sensitive application name to lookup.
relation_base_name (str) – Case insensitive name of the base model element.
- Returns:
Corresponding relation.
- Raises:
ValueError – If the relation does not exist.
- Return type:
odsbox.proto.ods_pb2.Model.Relation
- enumeration(enumeration_name)[source]¶
Get enumeration by its name.
- Parameters:
enumeration_name (str) – Case insensitive name of the application model enumeration.
- Returns:
Corresponding enumeration.
- Raises:
ValueError – If the enumeration does not exist.
- Return type:
odsbox.proto.ods_pb2.Model.Enumeration
- enumeration_value_to_key(enumeration_or_name, lookup_value)[source]¶
Convert an enumeration value into its string representation.
- Parameters:
enumeration_or_name (str | odsbox.proto.ods_pb2.Model.Enumeration) – ODS enumeration or its case insensitive name.
lookup_value (int) – Integer value to check.
- Returns:
String representation of int value.
- Raises:
ValueError – If the enumeration does not exist or does not contain value.
- Return type:
str
- enumeration_key_to_value(enumeration_or_name, lookup_key)[source]¶
Convert an enumeration integer value into its string representation.
- Parameters:
enumeration_or_name (str | odsbox.proto.ods_pb2.Model.Enumeration) – ODS enumeration or its case insensitive name.
lookup_key (str) – Case insensitive string key value to check.
- Returns:
Int representation of string value.
- Raises:
ValueError – If the enumeration does not exist or does not contain the key.
- Return type:
int