armodel 1.3.0__py3-none-any.whl → 1.4.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 (75) hide show
  1. armodel/__init__.py +2 -1
  2. armodel/cli/arxml_dump_cli.py +8 -6
  3. armodel/cli/arxml_format_cli.py +72 -0
  4. armodel/cli/connector2xlsx_cli.py +75 -0
  5. armodel/cli/connector_update_cli.py +77 -0
  6. armodel/cli/swc_list_cli.py +2 -2
  7. armodel/data_models/__init__.py +0 -0
  8. armodel/data_models/sw_connector.py +22 -0
  9. armodel/lib/__init__.py +1 -1
  10. armodel/lib/sw_component.py +34 -0
  11. armodel/models/__init__.py +8 -2
  12. armodel/models/annotation.py +20 -0
  13. armodel/models/ar_object.py +184 -0
  14. armodel/models/ar_package.py +144 -14
  15. armodel/models/ar_ref.py +74 -8
  16. armodel/models/bsw_module_template.py +97 -25
  17. armodel/models/calibration.py +119 -0
  18. armodel/models/common_structure.py +203 -36
  19. armodel/models/communication.py +17 -0
  20. armodel/models/data_def_properties.py +16 -0
  21. armodel/models/data_dictionary.py +46 -9
  22. armodel/models/data_prototype.py +24 -5
  23. armodel/models/datatype.py +86 -19
  24. armodel/models/end_to_end_protection.py +67 -0
  25. armodel/models/general_structure.py +72 -17
  26. armodel/models/global_constraints.py +40 -0
  27. armodel/models/implementation.py +80 -32
  28. armodel/models/m2_msr.py +82 -6
  29. armodel/models/multilanguage_data.py +42 -0
  30. armodel/models/per_instance_memory.py +14 -0
  31. armodel/models/port_interface.py +27 -4
  32. armodel/models/port_prototype.py +48 -23
  33. armodel/models/record_layout.py +118 -0
  34. armodel/models/service_mapping.py +11 -0
  35. armodel/models/service_needs.py +48 -0
  36. armodel/models/sw_component.py +257 -43
  37. armodel/models/unit.py +14 -0
  38. armodel/parser/abstract_arxml_parser.py +248 -0
  39. armodel/parser/arxml_parser.py +1550 -648
  40. armodel/parser/connector_xlsx_parser.py +190 -0
  41. armodel/parser/excel_parser.py +18 -0
  42. armodel/report/__init__.py +1 -0
  43. armodel/report/connector_xls_report.py +76 -0
  44. armodel/report/excel_report.py +42 -0
  45. armodel/tests/__init__.py +0 -0
  46. armodel/tests/test_armodel/__init__.py +0 -0
  47. armodel/tests/test_armodel/models/__init__.py +0 -0
  48. armodel/tests/test_armodel/models/test_ar_object.py +152 -0
  49. armodel/tests/test_armodel/models/test_ar_package.py +294 -0
  50. armodel/tests/test_armodel/models/test_ar_ref.py +74 -0
  51. armodel/tests/test_armodel/models/test_bsw_module_template.py +46 -0
  52. armodel/tests/test_armodel/models/test_common_structure.py +73 -0
  53. armodel/tests/test_armodel/models/test_data_dictionary.py +29 -0
  54. armodel/tests/test_armodel/models/test_data_prototype.py +86 -0
  55. armodel/tests/test_armodel/models/test_datatype.py +239 -0
  56. armodel/tests/test_armodel/models/test_general_structure.py +50 -0
  57. armodel/tests/test_armodel/models/test_implementation.py +26 -0
  58. armodel/tests/test_armodel/models/test_m2_msr.py +77 -0
  59. armodel/tests/test_armodel/models/test_port_interface.py +198 -0
  60. armodel/tests/test_armodel/models/test_port_prototype.py +14 -0
  61. armodel/tests/test_armodel/parser/__init__.py +0 -0
  62. armodel/tests/test_armodel/parser/test_arxml_parser.py +15 -0
  63. armodel/tests/test_armodel/parser/test_parse_bswmd.py +192 -0
  64. armodel/tests/test_armodel/parser/test_sw_components.py +93 -0
  65. armodel/writer/__init__.py +1 -0
  66. armodel/writer/abstract_arxml_writer.py +123 -0
  67. armodel/writer/arxml_writer.py +1755 -0
  68. {armodel-1.3.0.dist-info → armodel-1.4.3.dist-info}/METADATA +124 -4
  69. armodel-1.4.3.dist-info/RECORD +78 -0
  70. armodel-1.4.3.dist-info/entry_points.txt +7 -0
  71. armodel-1.3.0.dist-info/RECORD +0 -31
  72. armodel-1.3.0.dist-info/entry_points.txt +0 -4
  73. {armodel-1.3.0.dist-info → armodel-1.4.3.dist-info}/LICENSE +0 -0
  74. {armodel-1.3.0.dist-info → armodel-1.4.3.dist-info}/WHEEL +0 -0
  75. {armodel-1.3.0.dist-info → armodel-1.4.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,192 @@
1
+ import filecmp
2
+
3
+ from .... import AUTOSAR, ARPackage
4
+ from .... import ARXMLParser, ARXMLWriter
5
+
6
+ import logging
7
+
8
+ class TestBswMD:
9
+ def setup_method(self):
10
+ logger = logging.getLogger()
11
+ formatter = logging.Formatter('[%(levelname)s] : %(message)s')
12
+ logging.basicConfig(format='[%(levelname)s] : %(message)s', level = logging.DEBUG)
13
+ log_file = 'pytest_armodel.log'
14
+
15
+ file_handler = logging.FileHandler(log_file)
16
+ file_handler.setFormatter(formatter)
17
+ file_handler.setLevel(logging.DEBUG)
18
+ logger.addHandler(file_handler)
19
+
20
+ document = AUTOSAR.getInstance()
21
+ document.clear()
22
+ parser = ARXMLParser()
23
+ parser.load("src/armodel/tests/test_files/BswM_Bswmd.arxml", document)
24
+
25
+ def test_ar_packages(self):
26
+ document = AUTOSAR.getInstance()
27
+ root_pkgs = sorted(document.getARPackages(), key = lambda pkg: pkg.short_name)
28
+ assert(len(root_pkgs) == 2)
29
+ assert(root_pkgs[0].short_name == "AUTOSAR_BswM")
30
+ assert(root_pkgs[1].short_name == "EB_BswM_TxDxM1I14R0")
31
+
32
+ root_pkg_0_pkgs = sorted(root_pkgs[0].getARPackages(), key = lambda pkg: pkg.short_name)
33
+ assert(len(root_pkg_0_pkgs) == 3)
34
+
35
+ bsw_module_desc_pkg = root_pkg_0_pkgs[0] # type:ARPackage
36
+ assert(bsw_module_desc_pkg.short_name == "BswModuleDescriptions")
37
+
38
+ root_pkg_1_pkgs = root_pkgs[1].getARPackages()
39
+ assert(len(root_pkg_1_pkgs) == 1)
40
+
41
+ def test_bsw_module_description(self):
42
+ document = AUTOSAR.getInstance()
43
+
44
+ pkg = document.find("/AUTOSAR_BswM/BswModuleDescriptions") # type: ARPackage
45
+ bsw_module_descs = pkg.getBswModuleDescriptions()
46
+ assert(len(bsw_module_descs) == 1)
47
+
48
+ bsw_module_desc = bsw_module_descs[0]
49
+ assert(bsw_module_desc.short_name == "BswM")
50
+ assert(bsw_module_desc.module_id.getText() == "34")
51
+ assert(bsw_module_desc.module_id.getValue() == 34)
52
+
53
+ # verify the provided entries
54
+ assert(len(bsw_module_desc._implementedEntryRefs) == 2)
55
+ assert(bsw_module_desc._implementedEntryRefs[0].dest == "BSW-MODULE-ENTRY")
56
+ assert(bsw_module_desc._implementedEntryRefs[0].value == "/AUTOSAR_BswM/BswModuleEntrys/BswM_Init")
57
+ assert(bsw_module_desc._implementedEntryRefs[1].dest == "BSW-MODULE-ENTRY")
58
+ assert(bsw_module_desc._implementedEntryRefs[1].value == "/AUTOSAR_BswM/BswModuleEntrys/BswM_MainFunction")
59
+
60
+ assert(len(bsw_module_desc.getBswInternalBehaviors()) == 1)
61
+ behavior = bsw_module_desc.getBswInternalBehaviors()[0]
62
+ assert(behavior.short_name == "InternalBehavior_0")
63
+
64
+ assert(len(behavior.getDataTypeMappingRefs()) == 1)
65
+ data_type_mapping_ref = behavior.getDataTypeMappingRefs()[0]
66
+ assert(data_type_mapping_ref.dest == "DATA-TYPE-MAPPING-SET")
67
+ assert(data_type_mapping_ref.value == "/BswMMode/DataTypeMappingSets/BswMModeMapping")
68
+
69
+ assert(len(behavior.getExclusiveAreas()) == 1)
70
+ assert(behavior.getExclusiveAreas()[0].short_name == "SCHM_BSWM_EXCLUSIVE_AREA")
71
+
72
+ assert(len(behavior.getBswSchedulableEntities()) == 1)
73
+ entity = behavior.getBswSchedulableEntities()[0]
74
+ assert(entity.short_name == "BswM_MainFunction")
75
+ assert(entity.minimum_start_interval is not None)
76
+ assert(entity.minimum_start_interval_ms is not None)
77
+ assert(len(entity.getCanEnterExclusiveAreaRefs()) == 1)
78
+ assert(entity.getCanEnterExclusiveAreaRefs()[0].dest == "EXCLUSIVE-AREA")
79
+ assert(entity.getCanEnterExclusiveAreaRefs()[0].value == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0/SCHM_BSWM_EXCLUSIVE_AREA")
80
+ assert(entity.implemented_entry_ref.dest == "BSW-MODULE-ENTRY")
81
+ assert(entity.implemented_entry_ref.value == "/AUTOSAR_BswM/BswModuleEntrys/BswM_MainFunction")
82
+
83
+ assert(len(behavior.getBswTimingEvents()) == 1)
84
+ event = behavior.getBswTimingEvents()[0]
85
+ assert(event.short_name == "TimingEvent_MainFunction")
86
+ assert(event.startsOnEventRef.dest == "BSW-SCHEDULABLE-ENTITY")
87
+ assert(event.startsOnEventRef.value == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0/BswM_MainFunction")
88
+ assert(event.period.getValue() == 0.02)
89
+ assert(event.period.getText() == "0.02")
90
+ assert(event.periodMs == 20)
91
+
92
+ def test_bsw_module_entries(self):
93
+ document = AUTOSAR.getInstance()
94
+
95
+ pkg = document.find("/AUTOSAR_BswM/BswModuleEntrys") # type: ARPackage
96
+ entries = sorted(pkg.getBswModuleEntries(), key= lambda entry: entry.short_name)
97
+ assert(len(entries) == 2)
98
+
99
+ assert(entries[0].short_name == "BswM_Init")
100
+ assert(entries[0].service_id._value == 0)
101
+ assert(entries[0].is_reentrant.value == False)
102
+ assert(entries[0].is_synchronous.value == True)
103
+ assert(entries[0].call_type.getText() == "REGULAR")
104
+ assert(entries[0].execution_context.getText() == "UNSPECIFIED")
105
+ assert(entries[0].sw_service_impl_policy.getText() == "STANDARD")
106
+
107
+ assert(entries[1].short_name == "BswM_MainFunction")
108
+ assert(entries[1].service_id._value == 3)
109
+ assert(entries[1].is_reentrant.value == False)
110
+ assert(entries[1].is_synchronous.value == True)
111
+ assert(entries[1].call_type.getText() == "SCHEDULED")
112
+ assert(entries[1].execution_context.getText() == "TASK")
113
+ assert(entries[1].sw_service_impl_policy.getText() == "STANDARD")
114
+
115
+ def test_bsw_module_swc_bsw_mapping(self):
116
+ document = AUTOSAR.getInstance()
117
+
118
+ pkg = document.find("/AUTOSAR_BswM/SwcBswMappings") # type: ARPackage
119
+ mappings = pkg.getSwcBswMappings()
120
+ assert(len(mappings) == 1)
121
+
122
+ assert(mappings[0].bswBehaviorRef.dest == "BSW-INTERNAL-BEHAVIOR")
123
+ assert(mappings[0].bswBehaviorRef.value == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
124
+
125
+ assert(len(mappings[0].getRunnableMappings()) == 1)
126
+ runnable_mapping = mappings[0].getRunnableMappings()[0]
127
+ assert(runnable_mapping.bswEntityRef.dest == "BSW-SCHEDULABLE-ENTITY")
128
+ assert(runnable_mapping.bswEntityRef.value == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0/BswM_MainFunction")
129
+ assert(runnable_mapping.swcRunnableRef.dest == "RUNNABLE-ENTITY")
130
+ assert(runnable_mapping.swcRunnableRef.value == "/AUTOSAR_BswM/SwComponentTypes/BswM/BswMInternalBehavior/RES_MainFunction")
131
+
132
+ def test_bsw_module_implementation(self):
133
+ document = AUTOSAR.getInstance()
134
+
135
+ pkg = document.find("/EB_BswM_TxDxM1I14R0/Implementations") # type: ARPackage
136
+ assert(len(pkg.getBswImplementations()) == 1)
137
+ impl = pkg.getBswImplementations()[0]
138
+ assert(impl.short_name == "BswImplementation_0")
139
+ assert(len(impl.getCodeDescriptors()) == 1)
140
+
141
+ code_desc = impl.getCodeDescriptors()[0]
142
+ assert(code_desc.short_name == "Files")
143
+ assert(len(code_desc.getArtifactDescriptors()) == 21)
144
+ assert(len(code_desc.getArtifactDescriptors("SWSRC")) == 4)
145
+ assert(len(code_desc.getArtifactDescriptors("SWHDR")) == 15)
146
+ assert(len(code_desc.getArtifactDescriptors("SWMAKE")) == 2)
147
+
148
+ artifact_descs = sorted(code_desc.getArtifactDescriptors("SWMAKE"), key = lambda o: o.getShortLabel().getValue())
149
+ assert(artifact_descs[0].getShortLabel().getValue() == "make::BswM_defs.mak")
150
+ assert(artifact_descs[0].getCategory().getValue() == "SWMAKE")
151
+ assert(artifact_descs[1].getShortLabel().getValue() == "make::BswM_rules.mak")
152
+ assert(artifact_descs[1].getCategory().getValue() == "SWMAKE")
153
+
154
+ assert(impl.programming_language.getValue() == "C")
155
+
156
+ assert(impl._resource_consumption.short_name == "ResourceConsumption")
157
+ assert(len(impl._resource_consumption.getMemorySections()) == 8)
158
+
159
+ section = impl._resource_consumption.getMemorySection("CODE")
160
+ assert(section.short_name == "CODE")
161
+ assert(section.alignment == None)
162
+ assert(section.swAddrMethodRef.dest == "SW-ADDR-METHOD")
163
+ assert(section.swAddrMethodRef.value == "/AUTOSAR_MemMap/SwAddrMethods/CODE")
164
+
165
+ section = impl._resource_consumption.getMemorySection("VAR_NO_INIT_UNSPECIFIED")
166
+ assert(section.short_name == "VAR_NO_INIT_UNSPECIFIED")
167
+ assert(section.alignment.getText() == "UNSPECIFIED")
168
+ assert(section.swAddrMethodRef.dest == "SW-ADDR-METHOD")
169
+ assert(section.swAddrMethodRef.value == "/AUTOSAR_MemMap/SwAddrMethods/VAR_NOINIT")
170
+
171
+ assert(impl.vendor_id.getValue() == 1)
172
+ assert(impl.sw_version.getValue() == "1.14.1")
173
+ assert(impl.swc_bsw_mapping_ref.dest == "SWC-BSW-MAPPING")
174
+ assert(impl.swc_bsw_mapping_ref.value == "/AUTOSAR_BswM/SwcBswMappings/SwcBswMapping_0")
175
+ assert(impl.ar_release_version.getValue() == "4.0.3")
176
+ assert(impl.behavior_ref.dest == "BSW-INTERNAL-BEHAVIOR")
177
+ assert(impl.behavior_ref.value == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
178
+
179
+
180
+ def test_load_save(self):
181
+ document = AUTOSAR.getInstance()
182
+ document.clear()
183
+ parser = ARXMLParser()
184
+ parser.load("src/armodel/tests/test_files/SoftwareComponents.arxml", document)
185
+
186
+ writer = ARXMLWriter()
187
+ writer.save("data/generated.arxml", document)
188
+
189
+ assert(filecmp.cmp("src/armodel/tests/test_files/SoftwareComponents.arxml", "data/generated.arxml", shallow = False) == True)
190
+
191
+
192
+
@@ -0,0 +1,93 @@
1
+ import filecmp
2
+ from ....models.sw_component import CompositionSwComponentType
3
+ from ....writer.arxml_writer import ARXMLWriter
4
+ from ....parser.arxml_parser import ARXMLParser
5
+ from ....models.ar_package import AUTOSAR
6
+
7
+ class TestSWComponents:
8
+ def setup_method(self):
9
+ document = AUTOSAR.getInstance()
10
+ document.clear()
11
+ parser = ARXMLParser()
12
+ parser.load("src/armodel/tests/test_files/SoftwareComponents.arxml", document)
13
+
14
+ def test_ar_packages(self):
15
+ document = AUTOSAR.getInstance()
16
+ root_pkgs = sorted(document.getARPackages(), key = lambda pkg: pkg.short_name)
17
+
18
+ assert(len(root_pkgs) == 1)
19
+ assert("DemoApplication" == root_pkgs[0].short_name)
20
+
21
+ def test_composition_sw_component_types(self):
22
+ document = AUTOSAR.getInstance()
23
+ sw_component = document.find("/DemoApplication/SwComponentTypes/TopLevelComposition")
24
+ assert(sw_component.short_name == "TopLevelComposition")
25
+ assert(isinstance(sw_component, CompositionSwComponentType))
26
+ prototypes = sw_component.getPortPrototypes()
27
+ assert(len(prototypes) == 2)
28
+
29
+ def test_composition_sw_component_types_sw_connectors(self):
30
+ document = AUTOSAR.getInstance()
31
+ sw_component = document.find("/DemoApplication/SwComponentTypes/TopLevelComposition")
32
+ assert(isinstance(sw_component, CompositionSwComponentType))
33
+ assert(len(sw_component.getSwConnectors()) == 6)
34
+ assert(len(sw_component.getAssemblySwConnectors()) == 3)
35
+ assert(len(sw_component.getDelegationSwConnectors()) == 3)
36
+
37
+ connector_name_list = set()
38
+ for sw_connector in sw_component.getAssemblySwConnectors():
39
+ connector_name_list.add(sw_connector.short_name)
40
+
41
+ assert(connector_name_list == set(['a6a18805580c94537a4c82f6c289a4d', 'ac681652833fb4b12b920adab33a73b', 'ac681652833fb4b12b920adab33a73c']))
42
+
43
+ sw_component.removeElement("a6a18805580c94537a4c82f6c289a4d")
44
+ assert(len(sw_component.getAssemblySwConnectors()) == 2)
45
+
46
+ # remove all the AssemblySwConnector
47
+ sw_component.removeAllAssemblySwConnector()
48
+ assert(len(sw_component.getAssemblySwConnectors()) == 0)
49
+ assert(len(sw_component.getDelegationSwConnectors()) == 3)
50
+
51
+ # remove all the DelegationSwConnector
52
+ sw_component.removeAllDelegationSwConnector()
53
+ assert(len(sw_component.getAssemblySwConnectors()) == 0)
54
+ assert(len(sw_component.getDelegationSwConnectors()) == 0)
55
+
56
+ def test_software_components_arxml_loading_and_saving(self):
57
+ document = AUTOSAR.getInstance()
58
+ document.clear()
59
+ parser = ARXMLParser()
60
+ parser.load("src/armodel/tests/test_files/SoftwareComponents.arxml", document)
61
+
62
+ writer = ARXMLWriter()
63
+ writer.save("data/generated.arxml", document)
64
+
65
+ assert(filecmp.cmp("src/armodel/tests/test_files/SoftwareComponents.arxml", "data/generated.arxml", shallow = False) == True)
66
+
67
+ def test_software_components_arxml_loading_and_saving(self):
68
+ document = AUTOSAR.getInstance()
69
+ document.clear()
70
+ parser = ARXMLParser()
71
+ parser.load("src/armodel/tests/test_files/AUTOSAR_Datatypes.arxml", document)
72
+
73
+ writer = ARXMLWriter()
74
+ writer.save("data/generated_AUTOSAR_Datatypes.arxml", document)
75
+
76
+ assert(filecmp.cmp("src/armodel/tests/test_files/AUTOSAR_Datatypes.arxml", "data/generated_AUTOSAR_Datatypes.arxml", shallow = False) == True)
77
+
78
+ def test_bswm_bswmd_arxml_loading_and_saving(self):
79
+ document = AUTOSAR.getInstance()
80
+ document.clear()
81
+ parser = ARXMLParser()
82
+ parser.load("src/armodel/tests/test_files/BswM_Bswmd.arxml", document)
83
+
84
+ writer = ARXMLWriter()
85
+ writer.save("data/generated_BswM_Bswmd.arxml", document)
86
+
87
+ assert(filecmp.cmp("src/armodel/tests/test_files/BswM_Bswmd.arxml", "data/generated_BswM_Bswmd.arxml", shallow = False) == True)
88
+
89
+
90
+
91
+
92
+
93
+
@@ -0,0 +1 @@
1
+ from .arxml_writer import ARXMLWriter
@@ -0,0 +1,123 @@
1
+ from abc import ABCMeta
2
+ import re
3
+ from xml.dom import minidom
4
+ from colorama import Fore
5
+
6
+ import logging
7
+ import xml.etree.cElementTree as ET
8
+
9
+ from armodel.models.ar_ref import TRefType
10
+
11
+ from ..models.ar_object import ARBoolean, ARFloat, ARLiteral, ARNumerical, ARObject
12
+
13
+ class AbstractARXMLWriter:
14
+ __metaclass__ = ABCMeta
15
+
16
+ def __init__(self, options = None) -> None:
17
+ if type(self) == AbstractARXMLWriter:
18
+ raise NotImplementedError("AbstractARXMLWriter is an abstract class.")
19
+
20
+ self.options = {}
21
+ self.options['warning'] = False
22
+ self.options['version'] = "4.2.2"
23
+ self.logger = logging.getLogger()
24
+
25
+ self._processOptions(options=options)
26
+
27
+ self.nsmap = {
28
+ "xmlns": "http://autosar.org/schema/r4.0",
29
+ }
30
+
31
+ def _processOptions(self, options):
32
+ if options:
33
+ if 'warning' in options:
34
+ self.options['warning'] = options['warning']
35
+
36
+ def _raiseError(self, error_msg):
37
+ if (self.options['warning'] == True):
38
+ self.logger.error(Fore.RED + error_msg + Fore.WHITE)
39
+ else:
40
+ raise ValueError(error_msg)
41
+
42
+ def setARObjectAttributes(self, element: ET.Element, ar_obj: ARObject):
43
+ if ar_obj.timestamp is not None:
44
+ self.logger.debug("Timestamp: %s" % ar_obj.timestamp)
45
+ element.attrib['T'] = ar_obj.timestamp
46
+ if ar_obj.uuid is not None:
47
+ self.logger.debug("UUID: %s" % ar_obj.uuid)
48
+ element.attrib['UUID'] = ar_obj.uuid
49
+
50
+ '''
51
+ def setChildElementOptionalValue(self, element: ET.Element, key: str, value: str):
52
+ if value is not None:
53
+ child_element = ET.SubElement(element, key)
54
+ child_element.text = value
55
+ '''
56
+
57
+ '''
58
+ def setChildElementOptionalNumberValue(self, element: ET.Element, key: str, value: str):
59
+ if value is not None:
60
+ child_element = ET.SubElement(element, key)
61
+ child_element.text = str(value)
62
+ '''
63
+
64
+ def setChildElementOptionalNumericalValue(self, element: ET.Element, key: str, numerical: ARNumerical):
65
+ if numerical is not None:
66
+ child_element = ET.SubElement(element, key)
67
+ self.setARObjectAttributes(child_element, numerical)
68
+ child_element.text = numerical._text
69
+
70
+ def setChildElementOptionalLiteral(self, element: ET.Element, key: str, literal: ARLiteral):
71
+ if literal is not None:
72
+ child_element = ET.SubElement(element, key)
73
+ self.setARObjectAttributes(child_element, literal)
74
+ if literal._value is not None:
75
+ child_element.text = str(literal._value)
76
+
77
+ def setChildElementOptionalRefType(self, parent: ET.Element, child_tag_name: str, ref: TRefType):
78
+ if ref is not None:
79
+ child_tag = ET.SubElement(parent, child_tag_name)
80
+ if ref.dest is not None:
81
+ child_tag.attrib['DEST'] = ref.dest
82
+ if ref.value is not None:
83
+ child_tag.text = ref.value
84
+
85
+ def setChildElementOptionalFloatValue(self, element: ET.Element, key: str, value: ARFloat):
86
+ if value is not None:
87
+ child_element = ET.SubElement(element, key)
88
+ child_element.text = value.getText()
89
+
90
+ def setChildElementOptionalBooleanValue(self, element: ET.Element, key: str, value: ARBoolean) -> ET.Element:
91
+ child_element = None
92
+ if value is not None:
93
+ child_element = ET.SubElement(element, key)
94
+ self.setARObjectAttributes(child_element, value)
95
+ child_element.text = value.getText()
96
+ return element
97
+
98
+ def setChildElementOptionalLiteral(self, element: ET.Element, key: str, value: ARLiteral) -> ET.Element:
99
+ child_element = None
100
+ if value is not None:
101
+ child_element = ET.SubElement(element, key)
102
+ self.setARObjectAttributes(child_element, value)
103
+ child_element.text = value.getText()
104
+ return element
105
+
106
+ def patch_xml(self, xml: str) -> str:
107
+ #xml = xml.replace("<SW-DATA-DEF-PROPS-CONDITIONAL/>","<SW-DATA-DEF-PROPS-CONDITIONAL></SW-DATA-DEF-PROPS-CONDITIONAL>")
108
+ xml = re.sub(r"\<([\w-]+)\/\>",r"<\1></\1>", xml)
109
+ xml = re.sub(r"<((\w+)\s+\w+=\"\w+\")\/>", r"<\1></\2>", xml)
110
+ #xml = xml.replace("<USES-END-TO-END-PROTECTION>false</USES-END-TO-END-PROTECTION>", "<USES-END-TO-END-PROTECTION>0</USES-END-TO-END-PROTECTION>")
111
+ return xml
112
+
113
+ def saveToFile(self, filename, root: ET.Element):
114
+ xml = ET.tostring(root, encoding = "UTF-8", xml_declaration = True, short_empty_elements = False)
115
+
116
+ dom = minidom.parseString(xml.decode())
117
+ xml = dom.toprettyxml(indent = " ", encoding = "UTF-8")
118
+
119
+ text = self.patch_xml(xml.decode())
120
+
121
+ with open(filename, "w", encoding="utf-8") as f_out:
122
+ #f_out.write(xml.decode())
123
+ f_out.write(text)