armodel 1.8.2__py3-none-any.whl → 1.8.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. armodel/cli/format_xml_cli.py +62 -0
  2. armodel/models/M2/AUTOSARTemplates/CommonStructure/ImplementationDataTypes.py +17 -15
  3. armodel/models/M2/AUTOSARTemplates/CommonStructure/TriggerDeclaration.py +1 -1
  4. armodel/models/M2/AUTOSARTemplates/CommonStructure/__init__.py +44 -28
  5. armodel/models/M2/AUTOSARTemplates/GenericStructure/GeneralTemplateClasses/Identifiable.py +5 -5
  6. armodel/models/M2/AUTOSARTemplates/GenericStructure/GeneralTemplateClasses/PrimitiveTypes.py +13 -1
  7. armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/Communication.py +247 -45
  8. armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/SwcInternalBehavior/AutosarVariableRef.py +9 -6
  9. armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/SwcInternalBehavior/DataElements.py +7 -5
  10. armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/SwcInternalBehavior/RTEEvents.py +3 -3
  11. armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/SwcInternalBehavior/Trigger.py +43 -2
  12. armodel/models/M2/AUTOSARTemplates/SWComponentTemplate/SwcInternalBehavior/__init__.py +40 -43
  13. armodel/models/M2/MSR/AsamHdo/ComputationMethod.py +13 -12
  14. armodel/models/M2/MSR/DataDictionary/DataDefProperties.py +40 -9
  15. armodel/parser/abstract_arxml_parser.py +4 -0
  16. armodel/parser/arxml_parser.py +88 -56
  17. armodel/tests/test_armodel/models/test_common_structure.py +2 -2
  18. armodel/tests/test_armodel/parser/test_arxml_parser.py +38 -0
  19. armodel/tests/test_armodel/parser/test_implementation_data_type.py +247 -0
  20. armodel/tests/test_armodel/parser/test_rte_event.py +142 -0
  21. armodel/tests/test_armodel/parser/test_runnable_entity.py +135 -0
  22. armodel/writer/abstract_arxml_writer.py +2 -0
  23. armodel/writer/arxml_writer.py +89 -25
  24. {armodel-1.8.2.dist-info → armodel-1.8.3.dist-info}/METADATA +11 -1
  25. {armodel-1.8.2.dist-info → armodel-1.8.3.dist-info}/RECORD +29 -25
  26. {armodel-1.8.2.dist-info → armodel-1.8.3.dist-info}/entry_points.txt +1 -0
  27. {armodel-1.8.2.dist-info → armodel-1.8.3.dist-info}/LICENSE +0 -0
  28. {armodel-1.8.2.dist-info → armodel-1.8.3.dist-info}/WHEEL +0 -0
  29. {armodel-1.8.2.dist-info → armodel-1.8.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,62 @@
1
+ import argparse
2
+ import sys
3
+ import pkg_resources
4
+ import xml.etree.ElementTree as ET
5
+ from xml.dom import minidom
6
+ import logging
7
+ import re
8
+
9
+
10
+ def patch_xml(xml: str) -> str:
11
+ xml = re.sub(r"\<([\w-]+)\/\>", r"<\1></\1>", xml)
12
+ # xml = re.sub(r"<([\w-]+)\s+(\w+)=(\"[\w-]+\")\/>", r"<\1 \2=\3></\1>", xml)
13
+ # xml = re.sub(r"&quot;", '"', xml)
14
+ return xml
15
+
16
+
17
+ def perform_format(args):
18
+ try:
19
+ # Load XML file
20
+ logging.info("Loading XML file: %s" % args.INPUT)
21
+ tree = ET.parse(args.INPUT)
22
+ ET.register_namespace("", "http://autosar.org/schema/r4.0")
23
+ root = tree.getroot()
24
+
25
+ # Save the XML file
26
+ xml = ET.tostring(root, encoding="UTF-8", xml_declaration=True, short_empty_elements=False)
27
+
28
+ dom = minidom.parse(args.INPUT)
29
+ xml = dom.toprettyxml(indent=" ", encoding="UTF-8")
30
+
31
+ xml = patch_xml(xml.decode())
32
+
33
+ lines = xml.splitlines()
34
+
35
+ logging.info("Saving XML file: %s" % args.OUTPUT)
36
+
37
+ with open(args.OUTPUT, "w", encoding="utf-8") as f_out:
38
+ for line in lines:
39
+ if line.strip() == "":
40
+ continue
41
+ f_out.write(line + "\n")
42
+
43
+ except Exception as e:
44
+ logging.error(e)
45
+ sys.exit(1)
46
+
47
+
48
+ def main():
49
+ version = pkg_resources.require("armodel")[0].version
50
+
51
+ ap = argparse.ArgumentParser()
52
+ ap.description = "arxml-format ver: %s" % version
53
+ ap.add_argument("INPUT", help="The path of XML file")
54
+ ap.add_argument("OUTPUT", help="The path of XML file")
55
+
56
+ args = ap.parse_args()
57
+
58
+ perform_format(args)
59
+
60
+
61
+ if __name__ == "__main__":
62
+ main()
@@ -21,33 +21,34 @@ class ImplementationDataTypeElement(AbstractImplementationDataTypeElement):
21
21
  def __init__(self, parent, short_name: str):
22
22
  super().__init__(parent, short_name)
23
23
 
24
- self.arrayImplPolicy = None # type: ARLiteral
25
- self.arraySize = None # type: ARNumerical
26
- self.arraySizeHandling = None # type: ARLiteral
27
- self.arraySizeSemantics = None # type: ARLiteral
28
- self.isOptional = None # type: ARBoolean
29
- self.swDataDefProps = None # type: SwDataDefProps
30
-
31
- def getArrayImplPolicy(self):
24
+ self.arrayImplPolicy: ARLiteral = None
25
+ self.arraySize: ARNumerical = None
26
+ self.arraySizeHandling: ARLiteral = None
27
+ self.arraySizeSemantics: ARLiteral = None
28
+ self.isOptional: ARBoolean = None
29
+ self.subElements: List[ImplementationDataTypeElement] = []
30
+ self.swDataDefProps: SwDataDefProps = None
31
+
32
+ def getArrayImplPolicy(self) -> ARLiteral:
32
33
  return self.arrayImplPolicy
33
34
 
34
- def setArrayImplPolicy(self, value):
35
+ def setArrayImplPolicy(self, value: ARLiteral):
35
36
  if value is not None:
36
37
  self.arrayImplPolicy = value
37
38
  return self
38
39
 
39
- def getArraySize(self):
40
+ def getArraySize(self) -> ARNumerical:
40
41
  return self.arraySize
41
42
 
42
- def setArraySize(self, value):
43
+ def setArraySize(self, value: ARNumerical):
43
44
  if value is not None:
44
45
  self.arraySize = value
45
46
  return self
46
47
 
47
- def getArraySizeHandling(self):
48
+ def getArraySizeHandling(self) -> ARLiteral:
48
49
  return self.arraySizeHandling
49
50
 
50
- def setArraySizeHandling(self, value):
51
+ def setArraySizeHandling(self, value: ARLiteral):
51
52
  if value is not None:
52
53
  self.arraySizeHandling = value
53
54
  return self
@@ -80,10 +81,11 @@ class ImplementationDataTypeElement(AbstractImplementationDataTypeElement):
80
81
  if (not self.IsElementExists(short_name)):
81
82
  type_element = ImplementationDataTypeElement(self, short_name)
82
83
  self.addElement(type_element)
84
+ self.subElements.append(type_element)
83
85
  return self.getElement(short_name, ImplementationDataTypeElement)
84
86
 
85
- def getImplementationDataTypeElements(self) -> List["ImplementationDataTypeElement"]:
86
- return list(filter(lambda c: isinstance(c, ImplementationDataTypeElement), self.elements))
87
+ def getSubElements(self) -> List["ImplementationDataTypeElement"]:
88
+ return self.subElements
87
89
 
88
90
 
89
91
  class AbstractImplementationDataType(AutosarDataType, metaclass=ABCMeta):
@@ -8,7 +8,7 @@ class Trigger(Identifiable):
8
8
  def __init__(self, parent: ARObject, short_name: str):
9
9
  super().__init__(parent, short_name)
10
10
 
11
- self.swImplPolicy = None # type: SwImplPolicyEnum
11
+ self.swImplPolicy: SwImplPolicyEnum = None
12
12
  self.triggerPeriod = None # type: MultidimensionalTime
13
13
 
14
14
  def getSwImplPolicy(self):
@@ -1,23 +1,26 @@
1
1
  from abc import ABCMeta
2
2
  from typing import List
3
3
  from ....M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.ArObject import ARObject
4
- from ....M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.PrimitiveTypes import ARNumerical
4
+ from ....M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.PrimitiveTypes import ARNumerical, RefType
5
5
  from ....M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.Identifiable import ARElement
6
6
  from ....M2.AUTOSARTemplates.GenericStructure.GeneralTemplateClasses.PrimitiveTypes import ARLiteral
7
7
 
8
- class ValueSpecification(ARObject, metaclass = ABCMeta):
8
+
9
+ class ValueSpecification(ARObject, metaclass=ABCMeta):
9
10
  '''
10
11
  Base class for expressions leading to a value which can be used to initialize a data object.
11
-
12
+
12
13
  Base : ARObject
13
14
  Subclasses : AbstractRuleBasedValueSpecification, ApplicationValueSpecification, CompositeValueSpecification,
14
- ConstantReference, NotAvailableValueSpecification, NumericalValueSpecification, ReferenceValueSpecification,
15
+ ConstantReference, NotAvailableValueSpecification, NumericalValueSpecification, ReferenceValueSpecification,
15
16
  TextValueSpecification
16
17
  '''
18
+
17
19
  def __init__(self):
18
- if type(self) == ValueSpecification:
19
- raise NotImplementedError("ValueSpecification is an abstract class.")
20
-
20
+ if type(self) is ValueSpecification:
21
+ raise NotImplementedError(
22
+ "ValueSpecification is an abstract class.")
23
+
21
24
  super().__init__()
22
25
 
23
26
  self.shortLabel = None
@@ -28,21 +31,25 @@ class ValueSpecification(ARObject, metaclass = ABCMeta):
28
31
  def setShortLabel(self, value):
29
32
  self.shortLabel = value
30
33
  return self
31
-
32
- class CompositeValueSpecification(ValueSpecification, metaclass = ABCMeta):
34
+
35
+
36
+ class CompositeValueSpecification(ValueSpecification, metaclass=ABCMeta):
33
37
  '''
34
38
  This abstract meta-class acts a base class for ValueSpecifications that have a composite form.
35
39
 
36
40
  Base : ARObject, ValueSpecification
37
41
  Subclasses : ArrayValueSpecification, RecordValueSpecification
38
- '''
42
+ '''
43
+
39
44
  def __init__(self):
40
- if type(self) == CompositeValueSpecification:
41
- raise NotImplementedError("CompositeValueSpecification is an abstract class.")
42
-
43
- super().__init__()
45
+ if type(self) is CompositeValueSpecification:
46
+ raise NotImplementedError(
47
+ "CompositeValueSpecification is an abstract class.")
48
+
49
+ super().__init__()
50
+
44
51
 
45
- class CompositeRuleBasedValueArgument(ARObject, metaclass = ABCMeta):
52
+ class CompositeRuleBasedValueArgument(ARObject, metaclass=ABCMeta):
46
53
  '''
47
54
  This meta-class has the ability to serve as the abstract base class for ValueSpecifications that can be
48
55
  used for compound primitive data types.
@@ -50,12 +57,15 @@ class CompositeRuleBasedValueArgument(ARObject, metaclass = ABCMeta):
50
57
  Base : ARObject
51
58
  Subclasses : ApplicationRuleBasedValueSpecification, ApplicationValueSpecification
52
59
  '''
60
+
53
61
  def __init__(self):
54
- if type(self) == CompositeRuleBasedValueArgument:
55
- raise NotImplementedError("CompositeRuleBasedValueArgument is an abstract class.")
56
-
62
+ if type(self) is CompositeRuleBasedValueArgument:
63
+ raise NotImplementedError(
64
+ "CompositeRuleBasedValueArgument is an abstract class.")
65
+
57
66
  super().__init__()
58
67
 
68
+
59
69
  class ApplicationValueSpecification(CompositeRuleBasedValueArgument, ValueSpecification):
60
70
  '''
61
71
  This meta-class represents values for DataPrototypes typed by ApplicationDataTypes (this includes in
@@ -63,10 +73,11 @@ class ApplicationValueSpecification(CompositeRuleBasedValueArgument, ValueSpecif
63
73
  For further details refer to ASAM CDF 2.0. This meta-class corresponds to some extent with
64
74
  SW-INSTANCE in ASAM CDF 2.0.
65
75
 
66
- Base ARObject, CompositeRuleBasedValueArgument, ValueSpecification
76
+ Base ARObject, CompositeRuleBasedValueArgument, ValueSpecification
67
77
  '''
78
+
68
79
  def __init__(self):
69
-
80
+
70
81
  CompositeRuleBasedValueArgument.__init__(self)
71
82
  ValueSpecification.__init__(self)
72
83
 
@@ -99,9 +110,10 @@ class ApplicationValueSpecification(CompositeRuleBasedValueArgument, ValueSpecif
99
110
  class RecordValueSpecification(CompositeValueSpecification):
100
111
  '''
101
112
  Specifies the values for a record.
102
-
113
+
103
114
  Base : ARObject, CompositeValueSpecification, ValueSpecification
104
115
  '''
116
+
105
117
  def __init__(self):
106
118
  super().__init__()
107
119
 
@@ -112,7 +124,8 @@ class RecordValueSpecification(CompositeValueSpecification):
112
124
 
113
125
  def getFields(self) -> List[ValueSpecification]:
114
126
  return self.fields
115
-
127
+
128
+
116
129
  class TextValueSpecification(ValueSpecification):
117
130
  def __init__(self):
118
131
  super().__init__()
@@ -131,13 +144,14 @@ class NumericalValueSpecification(ValueSpecification):
131
144
  def __init__(self):
132
145
  super().__init__()
133
146
 
134
- self.value = None # type: ARNumerical
147
+ self.value: ARNumerical = None
135
148
 
136
- def getValue(self):
149
+ def getValue(self) -> ARNumerical:
137
150
  return self.value
138
151
 
139
- def setValue(self, value):
140
- self.value = value
152
+ def setValue(self, value: ARNumerical):
153
+ if value is not None:
154
+ self.value = value
141
155
  return self
142
156
 
143
157
 
@@ -145,7 +159,8 @@ class ArrayValueSpecification(ValueSpecification):
145
159
  def __init__(self):
146
160
  super().__init__()
147
161
 
148
- self.element = [] # type: List[ValueSpecification]
162
+ # type: List[ValueSpecification]
163
+ self.element = []
149
164
  self.intendedPartialInitializationCount = None
150
165
 
151
166
  def getIntendedPartialInitializationCount(self):
@@ -161,6 +176,7 @@ class ArrayValueSpecification(ValueSpecification):
161
176
  def getElements(self) -> List[ValueSpecification]:
162
177
  return self.element
163
178
 
179
+
164
180
  class ConstantSpecification(ARElement):
165
181
  def __init__(self, parent, short_name):
166
182
  super().__init__(parent, short_name)
@@ -179,7 +195,7 @@ class ConstantReference(ValueSpecification):
179
195
  def __init__(self):
180
196
  super().__init__()
181
197
 
182
- self.constantRef = None # type: RefType
198
+ self.constantRef: RefType = None
183
199
 
184
200
  def getConstantRef(self):
185
201
  return self.constantRef
@@ -122,11 +122,11 @@ class Identifiable(MultilanguageReferrable, CollectableElement, metaclass=ABCMet
122
122
  MultilanguageReferrable.__init__(self, parent, short_name)
123
123
  CollectableElement.__init__(self)
124
124
 
125
- self.annotations = [] # type: List[Annotation]
126
- self.adminData = None # type: AdminData
127
- self.category = None # type: CategoryString
128
- self.introduction = None # type: DocumentationBlock
129
- self.desc = None # type: MultiLanguageOverviewParagraph
125
+ self.annotations: List[Annotation] = []
126
+ self.adminData: AdminData = None
127
+ self.category: CategoryString = None
128
+ self.introduction: DocumentationBlock = None
129
+ self.desc: MultiLanguageOverviewParagraph = None
130
130
 
131
131
  def getAdminData(self):
132
132
  return self.adminData
@@ -34,7 +34,8 @@ class ARNumerical(ARType):
34
34
  def __init__(self) -> None:
35
35
  super().__init__()
36
36
 
37
- self._text = None # type: str
37
+ self.shortLabel: str = None
38
+ self._text: str = None
38
39
 
39
40
  def _convertStringToNumberValue(self, value: str) -> int:
40
41
  try:
@@ -75,7 +76,18 @@ class ARNumerical(ARType):
75
76
  return self._text
76
77
  else:
77
78
  return str(self._value)
79
+
80
+ def getValue(self):
81
+ return self.value
78
82
 
83
+ def setShortLabel(self, val: str):
84
+ if val is not None:
85
+ self.shortLabel = val
86
+ return self
87
+
88
+ def getShortLabel(self) -> str:
89
+ return self.shortLabel
90
+
79
91
 
80
92
  class ARFloat(ARNumerical):
81
93
  def __init__(self) -> None: