armodel 1.4.0__py3-none-any.whl → 1.5.0__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.
- armodel/__init__.py +2 -1
- armodel/cli/arxml_dump_cli.py +9 -7
- armodel/cli/arxml_format_cli.py +72 -0
- armodel/cli/connector_update_cli.py +11 -4
- armodel/data_models/__init__.py +0 -0
- armodel/data_models/sw_connector.py +22 -0
- armodel/lib/data_analyzer.py +1 -1
- armodel/models/__init__.py +3 -2
- armodel/models/annotation.py +20 -0
- armodel/models/ar_object.py +163 -18
- armodel/models/ar_package.py +228 -24
- armodel/models/ar_ref.py +85 -6
- armodel/models/bsw_module_template.py +113 -27
- armodel/models/calibration.py +107 -4
- armodel/models/common_structure.py +142 -52
- armodel/models/communication.py +10 -1
- armodel/models/data_def_properties.py +16 -0
- armodel/models/data_dictionary.py +46 -9
- armodel/models/data_prototype.py +24 -5
- armodel/models/datatype.py +69 -20
- armodel/models/end_to_end_protection.py +67 -0
- armodel/models/fibex/__init__.py +0 -0
- armodel/models/fibex/can_communication.py +6 -0
- armodel/models/fibex/fibex_4_multiplatform.py +145 -0
- armodel/models/fibex/fibex_core.py +341 -0
- armodel/models/fibex/lin_communication.py +17 -0
- armodel/models/fibex/lin_topology.py +7 -0
- armodel/models/general_structure.py +44 -18
- armodel/models/global_constraints.py +4 -4
- armodel/models/implementation.py +79 -32
- armodel/models/internal_behavior.py +63 -0
- armodel/models/m2_msr.py +6 -4
- armodel/models/mode_declaration.py +8 -0
- armodel/models/multilanguage_data.py +42 -0
- armodel/models/per_instance_memory.py +14 -0
- armodel/models/port_interface.py +27 -4
- armodel/models/port_prototype.py +57 -19
- armodel/models/record_layout.py +118 -0
- armodel/models/rpt_scenario.py +20 -0
- armodel/models/service_mapping.py +11 -0
- armodel/models/service_needs.py +48 -0
- armodel/models/sw_component.py +293 -45
- armodel/models/system_template/__init__.py +0 -0
- armodel/models/system_template/network_management.py +7 -0
- armodel/models/system_template/transport_protocols.py +7 -0
- armodel/models/timing.py +91 -0
- armodel/parser/abstract_arxml_parser.py +248 -0
- armodel/parser/arxml_parser.py +1571 -844
- armodel/parser/connector_xlsx_parser.py +190 -0
- armodel/parser/excel_parser.py +18 -0
- armodel/tests/test_armodel/models/test_ar_object.py +152 -0
- armodel/tests/test_armodel/models/test_ar_package.py +1 -1
- armodel/tests/test_armodel/models/test_common_structure.py +2 -2
- armodel/tests/test_armodel/models/test_data_dictionary.py +7 -7
- armodel/tests/test_armodel/models/test_data_prototype.py +3 -3
- armodel/tests/test_armodel/models/test_datatype.py +11 -11
- armodel/tests/test_armodel/models/test_general_structure.py +1 -1
- armodel/tests/test_armodel/models/test_implementation.py +26 -0
- armodel/tests/test_armodel/models/test_m2_msr.py +4 -4
- armodel/tests/test_armodel/models/test_port_interface.py +5 -5
- armodel/tests/test_armodel/parser/test_arxml_parser.py +15 -0
- armodel/tests/test_armodel/parser/test_parse_bswmd.py +74 -42
- armodel/tests/test_armodel/parser/test_sw_components.py +93 -0
- armodel/writer/abstract_arxml_writer.py +123 -0
- armodel/writer/arxml_writer.py +1701 -358
- {armodel-1.4.0.dist-info → armodel-1.5.0.dist-info}/METADATA +114 -3
- armodel-1.5.0.dist-info/RECORD +91 -0
- {armodel-1.4.0.dist-info → armodel-1.5.0.dist-info}/WHEEL +1 -1
- {armodel-1.4.0.dist-info → armodel-1.5.0.dist-info}/entry_points.txt +2 -0
- armodel-1.4.0.dist-info/RECORD +0 -60
- {armodel-1.4.0.dist-info → armodel-1.5.0.dist-info}/LICENSE +0 -0
- {armodel-1.4.0.dist-info → armodel-1.5.0.dist-info}/top_level.txt +0 -0
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
import filecmp
|
|
2
|
+
|
|
1
3
|
from .... import AUTOSAR, ARPackage
|
|
2
|
-
from .... import ARXMLParser
|
|
4
|
+
from .... import ARXMLParser, ARXMLWriter
|
|
3
5
|
|
|
4
6
|
import logging
|
|
5
7
|
|
|
6
8
|
class TestBswMD:
|
|
7
9
|
def setup_method(self):
|
|
10
|
+
logger = logging.getLogger()
|
|
11
|
+
formatter = logging.Formatter('[%(levelname)s] : %(message)s')
|
|
8
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)
|
|
9
19
|
|
|
10
20
|
document = AUTOSAR.getInstance()
|
|
11
21
|
document.clear()
|
|
@@ -37,14 +47,15 @@ class TestBswMD:
|
|
|
37
47
|
|
|
38
48
|
bsw_module_desc = bsw_module_descs[0]
|
|
39
49
|
assert(bsw_module_desc.short_name == "BswM")
|
|
40
|
-
assert(bsw_module_desc.module_id ==
|
|
50
|
+
assert(bsw_module_desc.module_id.getText() == "34")
|
|
51
|
+
assert(bsw_module_desc.module_id.getValue() == 34)
|
|
41
52
|
|
|
42
53
|
# verify the provided entries
|
|
43
|
-
assert(len(bsw_module_desc.
|
|
44
|
-
assert(bsw_module_desc.
|
|
45
|
-
assert(bsw_module_desc.
|
|
46
|
-
assert(bsw_module_desc.
|
|
47
|
-
assert(bsw_module_desc.
|
|
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")
|
|
48
59
|
|
|
49
60
|
assert(len(bsw_module_desc.getBswInternalBehaviors()) == 1)
|
|
50
61
|
behavior = bsw_module_desc.getBswInternalBehaviors()[0]
|
|
@@ -61,9 +72,9 @@ class TestBswMD:
|
|
|
61
72
|
assert(len(behavior.getBswSchedulableEntities()) == 1)
|
|
62
73
|
entity = behavior.getBswSchedulableEntities()[0]
|
|
63
74
|
assert(entity.short_name == "BswM_MainFunction")
|
|
64
|
-
assert(entity.minimum_start_interval
|
|
65
|
-
assert(entity.
|
|
66
|
-
assert(len(entity.getCanEnterExclusiveAreaRefs()) == 1)
|
|
75
|
+
assert(entity.minimum_start_interval is not None)
|
|
76
|
+
assert(entity.minimumStartIntervalMs is not None)
|
|
77
|
+
assert(len(entity.getCanEnterExclusiveAreaRefs()) == 1)
|
|
67
78
|
assert(entity.getCanEnterExclusiveAreaRefs()[0].dest == "EXCLUSIVE-AREA")
|
|
68
79
|
assert(entity.getCanEnterExclusiveAreaRefs()[0].value == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0/SCHM_BSWM_EXCLUSIVE_AREA")
|
|
69
80
|
assert(entity.implemented_entry_ref.dest == "BSW-MODULE-ENTRY")
|
|
@@ -72,10 +83,11 @@ class TestBswMD:
|
|
|
72
83
|
assert(len(behavior.getBswTimingEvents()) == 1)
|
|
73
84
|
event = behavior.getBswTimingEvents()[0]
|
|
74
85
|
assert(event.short_name == "TimingEvent_MainFunction")
|
|
75
|
-
assert(event.
|
|
76
|
-
assert(event.
|
|
77
|
-
assert(event.period == 0.02)
|
|
78
|
-
assert(event.
|
|
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)
|
|
79
91
|
|
|
80
92
|
def test_bsw_module_entries(self):
|
|
81
93
|
document = AUTOSAR.getInstance()
|
|
@@ -85,20 +97,20 @@ class TestBswMD:
|
|
|
85
97
|
assert(len(entries) == 2)
|
|
86
98
|
|
|
87
99
|
assert(entries[0].short_name == "BswM_Init")
|
|
88
|
-
assert(entries[0].service_id == 0)
|
|
100
|
+
assert(entries[0].service_id._value == 0)
|
|
89
101
|
assert(entries[0].is_reentrant.value == False)
|
|
90
102
|
assert(entries[0].is_synchronous.value == True)
|
|
91
|
-
assert(entries[0].call_type == "REGULAR")
|
|
92
|
-
assert(entries[0].execution_context == "UNSPECIFIED")
|
|
93
|
-
assert(entries[0].sw_service_impl_policy == "STANDARD")
|
|
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")
|
|
94
106
|
|
|
95
107
|
assert(entries[1].short_name == "BswM_MainFunction")
|
|
96
|
-
assert(entries[1].service_id == 3)
|
|
108
|
+
assert(entries[1].service_id._value == 3)
|
|
97
109
|
assert(entries[1].is_reentrant.value == False)
|
|
98
110
|
assert(entries[1].is_synchronous.value == True)
|
|
99
|
-
assert(entries[1].call_type == "SCHEDULED")
|
|
100
|
-
assert(entries[1].execution_context == "TASK")
|
|
101
|
-
assert(entries[1].sw_service_impl_policy == "STANDARD")
|
|
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")
|
|
102
114
|
|
|
103
115
|
def test_bsw_module_swc_bsw_mapping(self):
|
|
104
116
|
document = AUTOSAR.getInstance()
|
|
@@ -107,15 +119,15 @@ class TestBswMD:
|
|
|
107
119
|
mappings = pkg.getSwcBswMappings()
|
|
108
120
|
assert(len(mappings) == 1)
|
|
109
121
|
|
|
110
|
-
assert(mappings[0].
|
|
111
|
-
assert(mappings[0].
|
|
122
|
+
assert(mappings[0].bswBehaviorRef.dest == "BSW-INTERNAL-BEHAVIOR")
|
|
123
|
+
assert(mappings[0].bswBehaviorRef.value == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
|
|
112
124
|
|
|
113
125
|
assert(len(mappings[0].getRunnableMappings()) == 1)
|
|
114
126
|
runnable_mapping = mappings[0].getRunnableMappings()[0]
|
|
115
|
-
assert(runnable_mapping.
|
|
116
|
-
assert(runnable_mapping.
|
|
117
|
-
assert(runnable_mapping.
|
|
118
|
-
assert(runnable_mapping.
|
|
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")
|
|
119
131
|
|
|
120
132
|
def test_bsw_module_implementation(self):
|
|
121
133
|
document = AUTOSAR.getInstance()
|
|
@@ -133,13 +145,13 @@ class TestBswMD:
|
|
|
133
145
|
assert(len(code_desc.getArtifactDescriptors("SWHDR")) == 15)
|
|
134
146
|
assert(len(code_desc.getArtifactDescriptors("SWMAKE")) == 2)
|
|
135
147
|
|
|
136
|
-
artifact_descs = sorted(code_desc.getArtifactDescriptors("SWMAKE"), key= lambda o: o.
|
|
137
|
-
assert(artifact_descs[0].
|
|
138
|
-
assert(artifact_descs[0].
|
|
139
|
-
assert(artifact_descs[1].
|
|
140
|
-
assert(artifact_descs[1].
|
|
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")
|
|
141
153
|
|
|
142
|
-
assert(impl.programming_language == "C")
|
|
154
|
+
assert(impl.programming_language.getValue() == "C")
|
|
143
155
|
|
|
144
156
|
assert(impl.resource_consumption.short_name == "ResourceConsumption")
|
|
145
157
|
assert(len(impl.resource_consumption.getMemorySections()) == 8)
|
|
@@ -147,22 +159,42 @@ class TestBswMD:
|
|
|
147
159
|
section = impl.resource_consumption.getMemorySection("CODE")
|
|
148
160
|
assert(section.short_name == "CODE")
|
|
149
161
|
assert(section.alignment == None)
|
|
150
|
-
assert(section.
|
|
151
|
-
assert(section.
|
|
162
|
+
assert(section.swAddrMethodRef.dest == "SW-ADDR-METHOD")
|
|
163
|
+
assert(section.swAddrMethodRef.value == "/AUTOSAR_MemMap/SwAddrMethods/CODE")
|
|
152
164
|
|
|
153
165
|
section = impl.resource_consumption.getMemorySection("VAR_NO_INIT_UNSPECIFIED")
|
|
154
166
|
assert(section.short_name == "VAR_NO_INIT_UNSPECIFIED")
|
|
155
|
-
assert(section.alignment == "UNSPECIFIED")
|
|
156
|
-
assert(section.
|
|
157
|
-
assert(section.
|
|
167
|
+
assert(section.alignment.getText() == "UNSPECIFIED")
|
|
168
|
+
assert(section.swAddrMethodRef.dest == "SW-ADDR-METHOD")
|
|
169
|
+
assert(section.swAddrMethodRef.value == "/AUTOSAR_MemMap/SwAddrMethods/VAR_NOINIT")
|
|
158
170
|
|
|
159
|
-
assert(impl.vendor_id == 1)
|
|
160
|
-
assert(impl.sw_version == "1.14.1")
|
|
171
|
+
assert(impl.vendor_id.getValue() == 1)
|
|
172
|
+
assert(impl.sw_version.getValue() == "1.14.1")
|
|
161
173
|
assert(impl.swc_bsw_mapping_ref.dest == "SWC-BSW-MAPPING")
|
|
162
174
|
assert(impl.swc_bsw_mapping_ref.value == "/AUTOSAR_BswM/SwcBswMappings/SwcBswMapping_0")
|
|
163
|
-
assert(impl.ar_release_version == "4.0.3")
|
|
175
|
+
assert(impl.ar_release_version.getValue() == "4.0.3")
|
|
164
176
|
assert(impl.behavior_ref.dest == "BSW-INTERNAL-BEHAVIOR")
|
|
165
177
|
assert(impl.behavior_ref.value == "/AUTOSAR_BswM/BswModuleDescriptions/BswM/InternalBehavior_0")
|
|
166
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
|
+
def test_bswm_bswmd_arxml_loading_and_saving(self):
|
|
192
|
+
document = AUTOSAR.getInstance()
|
|
193
|
+
document.clear()
|
|
194
|
+
parser = ARXMLParser()
|
|
195
|
+
parser.load("src/armodel/tests/test_files/BswM_Bswmd.arxml", document)
|
|
167
196
|
|
|
197
|
+
writer = ARXMLWriter()
|
|
198
|
+
writer.save("data/generated_BswM_Bswmd.arxml", document)
|
|
168
199
|
|
|
200
|
+
assert(filecmp.cmp("src/armodel/tests/test_files/BswM_Bswmd.arxml", "data/generated_BswM_Bswmd.arxml", shallow = False) == True)
|
|
@@ -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_mode_arxml_loading_and_saving(self):
|
|
79
|
+
document = AUTOSAR.getInstance()
|
|
80
|
+
document.clear()
|
|
81
|
+
parser = ARXMLParser()
|
|
82
|
+
parser.load("src/armodel/tests/test_files/BswMMode.arxml", document)
|
|
83
|
+
|
|
84
|
+
writer = ARXMLWriter()
|
|
85
|
+
writer.save("data/generated_AUTOSAR_Datatypes.arxml", document)
|
|
86
|
+
|
|
87
|
+
assert(filecmp.cmp("src/armodel/tests/test_files/BswMMode.arxml", "data/generated_AUTOSAR_Datatypes.arxml", shallow = False) == True)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
@@ -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)
|