py-eb-model 0.8.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.
- eb_model/__init__.py +3 -0
- eb_model/cli/__init__.py +0 -0
- eb_model/cli/os_xdm_2_xls_cli.py +59 -0
- eb_model/models/__init__.py +3 -0
- eb_model/models/abstract.py +66 -0
- eb_model/models/eb_doc.py +52 -0
- eb_model/models/os_xdm.py +220 -0
- eb_model/parser/__init__.py +1 -0
- eb_model/parser/eb_parser.py +147 -0
- eb_model/parser/os_xdm_parser.py +43 -0
- eb_model/reporter/__init__.py +1 -0
- eb_model/reporter/excel_reporter/__init__.py +0 -0
- eb_model/reporter/excel_reporter/abstract.py +43 -0
- eb_model/reporter/excel_reporter/os_xdm.py +44 -0
- eb_model/reporter/markdown.py +40 -0
- eb_model/tests/__init__.py +0 -0
- eb_model/tests/models/__init__.py +0 -0
- eb_model/tests/models/test_eb_model.py +25 -0
- eb_model/tests/models/test_ecuc_container.py +22 -0
- py_eb_model-0.8.0.dist-info/LICENSE +21 -0
- py_eb_model-0.8.0.dist-info/METADATA +62 -0
- py_eb_model-0.8.0.dist-info/RECORD +25 -0
- py_eb_model-0.8.0.dist-info/WHEEL +5 -0
- py_eb_model-0.8.0.dist-info/entry_points.txt +2 -0
- py_eb_model-0.8.0.dist-info/top_level.txt +1 -0
eb_model/__init__.py
ADDED
eb_model/cli/__init__.py
ADDED
File without changes
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import argparse
|
2
|
+
import pkg_resources
|
3
|
+
import logging
|
4
|
+
import sys
|
5
|
+
import os.path
|
6
|
+
|
7
|
+
from ..parser import OsXdmParser
|
8
|
+
from ..models import EBModel
|
9
|
+
from ..reporter import OsXdmXlsWriter
|
10
|
+
|
11
|
+
def main():
|
12
|
+
version = pkg_resources.require("py_eb_model")[0].version
|
13
|
+
|
14
|
+
ap = argparse.ArgumentParser()
|
15
|
+
ap.add_argument("-v", "--verbose", required= False, help= "Print debug information", action= "store_true")
|
16
|
+
ap.add_argument("INPUT", help = "The path of Os.xdm.")
|
17
|
+
ap.add_argument("OUTPUT", help = "The path of excel file.")
|
18
|
+
|
19
|
+
args = ap.parse_args()
|
20
|
+
|
21
|
+
logger = logging.getLogger()
|
22
|
+
|
23
|
+
formatter = logging.Formatter('[%(levelname)s] : %(message)s')
|
24
|
+
|
25
|
+
stdout_handler = logging.StreamHandler(sys.stderr)
|
26
|
+
stdout_handler.setFormatter(formatter)
|
27
|
+
|
28
|
+
base_path = os.path.dirname(args.OUTPUT)
|
29
|
+
log_file = os.path.join(base_path, 'os_xdm_2_xls.log')
|
30
|
+
|
31
|
+
if os.path.exists(log_file):
|
32
|
+
os.remove(log_file)
|
33
|
+
|
34
|
+
file_handler = logging.FileHandler(log_file)
|
35
|
+
file_handler.setFormatter(formatter)
|
36
|
+
|
37
|
+
logger.setLevel(logging.DEBUG)
|
38
|
+
file_handler.setLevel(logging.DEBUG)
|
39
|
+
|
40
|
+
if args.verbose:
|
41
|
+
stdout_handler.setLevel(logging.DEBUG)
|
42
|
+
|
43
|
+
else:
|
44
|
+
stdout_handler.setLevel(logging.INFO)
|
45
|
+
|
46
|
+
logger.addHandler(file_handler)
|
47
|
+
logger.addHandler(stdout_handler)
|
48
|
+
|
49
|
+
try:
|
50
|
+
doc = EBModel.getInstance()
|
51
|
+
parser = OsXdmParser()
|
52
|
+
writer = OsXdmXlsWriter()
|
53
|
+
|
54
|
+
parser.parse(args.INPUT, doc)
|
55
|
+
writer.write(args.OUTPUT, doc)
|
56
|
+
|
57
|
+
except Exception as e:
|
58
|
+
logger.error(e)
|
59
|
+
raise e
|
@@ -0,0 +1,66 @@
|
|
1
|
+
from abc import ABCMeta
|
2
|
+
from typing import Dict, List
|
3
|
+
|
4
|
+
|
5
|
+
class EcucObject(metaclass=ABCMeta):
|
6
|
+
def __init__(self, parent, name) -> None:
|
7
|
+
if type(self) == EcucObject:
|
8
|
+
raise ValueError("Abstract EcucObject cannot be initialized.")
|
9
|
+
|
10
|
+
self.Name = name
|
11
|
+
self.Parent = parent # type: EcucObject
|
12
|
+
|
13
|
+
if isinstance(parent, EcucContainer):
|
14
|
+
parent.addElement(self)
|
15
|
+
|
16
|
+
def getName(self):
|
17
|
+
return self.Name
|
18
|
+
|
19
|
+
def setName(self, value):
|
20
|
+
self.Name = value
|
21
|
+
return self
|
22
|
+
|
23
|
+
def getParent(self):
|
24
|
+
return self.Parent
|
25
|
+
|
26
|
+
def setParent(self, value):
|
27
|
+
self.Parent = value
|
28
|
+
return self
|
29
|
+
|
30
|
+
def getFullName(self) -> str:
|
31
|
+
return self.Parent.getFullName() + "/" + self.Name
|
32
|
+
|
33
|
+
|
34
|
+
class EcucContainer(EcucObject):
|
35
|
+
def __init__(self, parent, name) -> None:
|
36
|
+
super().__init__(parent, name)
|
37
|
+
|
38
|
+
self.elements = {} # type: Dict[str, EcucObject]
|
39
|
+
|
40
|
+
def getTotalElement(self) -> int:
|
41
|
+
#return len(list(filter(lambda a: not isinstance(a, ARPackage) , self.elements.values())))
|
42
|
+
return len(self.elements)
|
43
|
+
|
44
|
+
def addElement(self, object: EcucObject):
|
45
|
+
if object.getName() not in self.elements:
|
46
|
+
object.Parent = self
|
47
|
+
self.elements[object.getName()] = object
|
48
|
+
|
49
|
+
return self
|
50
|
+
|
51
|
+
def removeElement(self, key):
|
52
|
+
if key not in self.elements:
|
53
|
+
raise KeyError("Invalid key <%s> for removing element" % key)
|
54
|
+
self.elements.pop(key)
|
55
|
+
|
56
|
+
def getElementList(self):
|
57
|
+
return self.elements.values()
|
58
|
+
|
59
|
+
def getElement(self, name: str) -> EcucObject:
|
60
|
+
if (name not in self.elements):
|
61
|
+
return None
|
62
|
+
return self.elements[name]
|
63
|
+
|
64
|
+
class EcucRefType:
|
65
|
+
def __init__(self) -> None:
|
66
|
+
self.link = ""
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
from typing import List
|
3
|
+
|
4
|
+
from .os_xdm import Os
|
5
|
+
from .abstract import EcucContainer, EcucObject
|
6
|
+
|
7
|
+
|
8
|
+
class EBModel(EcucContainer):
|
9
|
+
__instance = None
|
10
|
+
|
11
|
+
@staticmethod
|
12
|
+
def getInstance():
|
13
|
+
if (EBModel.__instance == None):
|
14
|
+
EBModel()
|
15
|
+
return EBModel.__instance
|
16
|
+
|
17
|
+
def __init__(self):
|
18
|
+
if (EBModel.__instance != None):
|
19
|
+
raise Exception("The EBModel is singleton!")
|
20
|
+
|
21
|
+
EcucContainer.__init__(self, None, "")
|
22
|
+
EBModel.__instance = self
|
23
|
+
|
24
|
+
def getFullName(self):
|
25
|
+
return self.Name
|
26
|
+
|
27
|
+
def clear(self):
|
28
|
+
self.elements = {}
|
29
|
+
|
30
|
+
def find(self, referred_name: str) -> EcucObject:
|
31
|
+
name_list = referred_name.split("/")
|
32
|
+
element = EBModel.getInstance()
|
33
|
+
for name in name_list:
|
34
|
+
if (name == ""):
|
35
|
+
continue
|
36
|
+
element = element.getElement(name)
|
37
|
+
if (element == None):
|
38
|
+
return element
|
39
|
+
# raise ValueError("The %s of reference <%s> does not exist." % (short_name, referred_name))
|
40
|
+
return element
|
41
|
+
|
42
|
+
def getOs(self) -> Os:
|
43
|
+
container = EcucContainer(self, "Os")
|
44
|
+
os = Os(container)
|
45
|
+
return self.find("/Os/Os")
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
@@ -0,0 +1,220 @@
|
|
1
|
+
from typing import List
|
2
|
+
|
3
|
+
from ..models.abstract import EcucObject
|
4
|
+
|
5
|
+
class OsApplication:
|
6
|
+
def __init__(self) -> None:
|
7
|
+
pass
|
8
|
+
|
9
|
+
class OsCounter:
|
10
|
+
def __init__(self) -> None:
|
11
|
+
pass
|
12
|
+
|
13
|
+
class OsResource:
|
14
|
+
def __init__(self) -> None:
|
15
|
+
pass
|
16
|
+
|
17
|
+
class OsIsrResourceLock:
|
18
|
+
def __init__(self) -> None:
|
19
|
+
self.OsIsrResourceLockBudget = None
|
20
|
+
self.OsIsrResourceLockResourceRef = None
|
21
|
+
|
22
|
+
|
23
|
+
class OsIsrTimingProtection:
|
24
|
+
def __init__(self) -> None:
|
25
|
+
self.OsIsrAllInterruptLockBudget = None
|
26
|
+
self.OsIsrExecutionBudget = None
|
27
|
+
self.OsIsrOsInterruptLockBudget = None
|
28
|
+
self.OsIsrTimeFrame = None
|
29
|
+
self.OsIsrResourceLock = OsIsrResourceLock()
|
30
|
+
|
31
|
+
class OsIsr(EcucObject):
|
32
|
+
'''
|
33
|
+
The OsIsr container represents an ISO 17356 interrupt service routine.
|
34
|
+
'''
|
35
|
+
|
36
|
+
OS_ISR_CATEGORY_1 = "CATEGORY_1" # Interrupt is of category 1
|
37
|
+
OS_ISR_CATEGORY_2 = "CATEGORY_2" # Interrupt is of category 2
|
38
|
+
|
39
|
+
def __init__(self) -> None:
|
40
|
+
self.OsIsrCategory = None
|
41
|
+
self.OsIsrPeriod = None
|
42
|
+
self.OsIsrResourceRef = None
|
43
|
+
self.OsMemoryMappingCodeLocationRef = None
|
44
|
+
self.OsIsrTimingProtection = OsIsrTimingProtection() # type: OsIsrTimingProtection
|
45
|
+
|
46
|
+
self.OsIsrPriority = None
|
47
|
+
self.OsStacksize = None
|
48
|
+
|
49
|
+
def getOsIsrCategory(self):
|
50
|
+
return self.OsIsrCategory
|
51
|
+
|
52
|
+
def setOsIsrCategory(self, value):
|
53
|
+
self.OsIsrCategory = value
|
54
|
+
return self
|
55
|
+
|
56
|
+
def getOsIsrPeriod(self):
|
57
|
+
return self.OsIsrPeriod
|
58
|
+
|
59
|
+
def setOsIsrPeriod(self, value):
|
60
|
+
self.OsIsrPeriod = value
|
61
|
+
return self
|
62
|
+
|
63
|
+
def getOsIsrResourceRef(self):
|
64
|
+
return self.OsIsrResourceRef
|
65
|
+
|
66
|
+
def setOsIsrResourceRef(self, value):
|
67
|
+
self.OsIsrResourceRef = value
|
68
|
+
return self
|
69
|
+
|
70
|
+
def getOsMemoryMappingCodeLocationRef(self):
|
71
|
+
return self.OsMemoryMappingCodeLocationRef
|
72
|
+
|
73
|
+
def setOsMemoryMappingCodeLocationRef(self, value):
|
74
|
+
self.OsMemoryMappingCodeLocationRef = value
|
75
|
+
return self
|
76
|
+
|
77
|
+
def getOsIsrTimingProtection(self):
|
78
|
+
return self.OsIsrTimingProtection
|
79
|
+
|
80
|
+
def setOsIsrTimingProtection(self, value):
|
81
|
+
self.OsIsrTimingProtection = value
|
82
|
+
return self
|
83
|
+
|
84
|
+
def getOsIsrPriority(self):
|
85
|
+
return self.OsIsrPriority
|
86
|
+
|
87
|
+
def setOsIsrPriority(self, value):
|
88
|
+
self.OsIsrPriority = value
|
89
|
+
return self
|
90
|
+
|
91
|
+
def getOsStacksize(self):
|
92
|
+
return self.OsStacksize
|
93
|
+
|
94
|
+
def setOsStacksize(self, value):
|
95
|
+
self.OsStacksize = value
|
96
|
+
return self
|
97
|
+
|
98
|
+
class OsTaskAutostart:
|
99
|
+
def __init__(self) -> None:
|
100
|
+
self.OsTaskAppModeRef = None
|
101
|
+
|
102
|
+
class OsTaskResourceLock:
|
103
|
+
def __init__(self) -> None:
|
104
|
+
self.OsTaskResourceLockBudget = None
|
105
|
+
|
106
|
+
class OsTaskTimingProtection:
|
107
|
+
def __init__(self) -> None:
|
108
|
+
self.OsTaskAllInterruptLockBudget = None
|
109
|
+
self.OsTaskExecutionBudget = None
|
110
|
+
self.OsTaskOsInterruptLockBudget = None
|
111
|
+
self.OsTaskTimeFrame = None
|
112
|
+
|
113
|
+
class OsTimeConstant:
|
114
|
+
def __init__(self) -> None:
|
115
|
+
self.OsTimeValue
|
116
|
+
|
117
|
+
class OsTask(EcucObject):
|
118
|
+
|
119
|
+
FULL = "FULL" # Task is preemptable.
|
120
|
+
NON = "NON" # Task is not preemptable.
|
121
|
+
|
122
|
+
def __init__(self) -> None:
|
123
|
+
self.OsTaskActivation = None # type: int
|
124
|
+
self.OsTaskPeriod = 0.0 # type: float
|
125
|
+
self.OsTaskPriority = None # type: int
|
126
|
+
self.OsTaskSchedule = ""
|
127
|
+
self.OsStacksize = 0 # type: int
|
128
|
+
self.OsMemoryMappingCodeLocationRef = None
|
129
|
+
self.OsTaskAccessingApplication = None
|
130
|
+
self.OsTaskEventRef = None
|
131
|
+
self.OsTaskResourceRef = None
|
132
|
+
|
133
|
+
def getOsTaskActivation(self):
|
134
|
+
return self.OsTaskActivation
|
135
|
+
|
136
|
+
def setOsTaskActivation(self, value):
|
137
|
+
self.OsTaskActivation = value
|
138
|
+
return self
|
139
|
+
|
140
|
+
def getOsTaskPeriod(self):
|
141
|
+
return self.OsTaskPeriod
|
142
|
+
|
143
|
+
def setOsTaskPeriod(self, value):
|
144
|
+
self.OsTaskPeriod = value
|
145
|
+
return self
|
146
|
+
|
147
|
+
def getOsTaskPriority(self):
|
148
|
+
return self.OsTaskPriority
|
149
|
+
|
150
|
+
def setOsTaskPriority(self, value):
|
151
|
+
self.OsTaskPriority = value
|
152
|
+
return self
|
153
|
+
|
154
|
+
def getOsTaskSchedule(self):
|
155
|
+
return self.OsTaskSchedule
|
156
|
+
|
157
|
+
def setOsTaskSchedule(self, value):
|
158
|
+
self.OsTaskSchedule = value
|
159
|
+
return self
|
160
|
+
|
161
|
+
def getOsStacksize(self):
|
162
|
+
return self.OsStacksize
|
163
|
+
|
164
|
+
def setOsStacksize(self, value):
|
165
|
+
self.OsStacksize = value
|
166
|
+
return self
|
167
|
+
|
168
|
+
def getOsMemoryMappingCodeLocationRef(self):
|
169
|
+
return self.OsMemoryMappingCodeLocationRef
|
170
|
+
|
171
|
+
def setOsMemoryMappingCodeLocationRef(self, value):
|
172
|
+
self.OsMemoryMappingCodeLocationRef = value
|
173
|
+
return self
|
174
|
+
|
175
|
+
def getOsTaskAccessingApplication(self):
|
176
|
+
return self.OsTaskAccessingApplication
|
177
|
+
|
178
|
+
def setOsTaskAccessingApplication(self, value):
|
179
|
+
self.OsTaskAccessingApplication = value
|
180
|
+
return self
|
181
|
+
|
182
|
+
def getOsTaskEventRef(self):
|
183
|
+
return self.OsTaskEventRef
|
184
|
+
|
185
|
+
def setOsTaskEventRef(self, value):
|
186
|
+
self.OsTaskEventRef = value
|
187
|
+
return self
|
188
|
+
|
189
|
+
def getOsTaskResourceRef(self):
|
190
|
+
return self.OsTaskResourceRef
|
191
|
+
|
192
|
+
def setOsTaskResourceRef(self, value):
|
193
|
+
self.OsTaskResourceRef = value
|
194
|
+
return self
|
195
|
+
|
196
|
+
def IsPreemptable(self) -> bool:
|
197
|
+
if self.OsTaskSchedule == OsTask.FULL:
|
198
|
+
return True
|
199
|
+
return False
|
200
|
+
|
201
|
+
class Os(EcucObject):
|
202
|
+
def __init__(self, parent) -> None:
|
203
|
+
super().__init__(parent, "Os")
|
204
|
+
|
205
|
+
self.osTasks = [] # type: List[OsTask]
|
206
|
+
self.osIsrs = [] # type: List[OsIsr]
|
207
|
+
|
208
|
+
def getOsTaskList(self) -> List[OsTask]:
|
209
|
+
return self.osTasks
|
210
|
+
|
211
|
+
def addOsTask(self, os_task: OsTask):
|
212
|
+
self.osTasks.append(os_task)
|
213
|
+
return self
|
214
|
+
|
215
|
+
def getOsIsrList(self) -> List[OsIsr]:
|
216
|
+
return self.osIsrs
|
217
|
+
|
218
|
+
def addOsIsr(self, os_isr: OsIsr):
|
219
|
+
self.osIsrs.append(os_isr)
|
220
|
+
return self
|
@@ -0,0 +1 @@
|
|
1
|
+
from .os_xdm_parser import OsXdmParser
|
@@ -0,0 +1,147 @@
|
|
1
|
+
#from xml.etree import cElementTree as ET
|
2
|
+
import xml.etree.ElementTree as ET
|
3
|
+
import re
|
4
|
+
|
5
|
+
from abc import ABCMeta
|
6
|
+
from typing import List
|
7
|
+
|
8
|
+
class EBModelParser(metaclass = ABCMeta):
|
9
|
+
|
10
|
+
def __init__(self) -> None:
|
11
|
+
self.ns = {}
|
12
|
+
|
13
|
+
if type(self) == "EBModelParser":
|
14
|
+
raise ValueError("Abstract EBModelParser cannot be initialized.")
|
15
|
+
|
16
|
+
def validate_root(self, element: ET.Element):
|
17
|
+
if (element.tag != "{%s}%s" % (self.ns[''], "datamodel")):
|
18
|
+
raise ValueError("This document <%s> is not EB xdm format" % element.tag)
|
19
|
+
|
20
|
+
def read_ref_raw_value(self, value):
|
21
|
+
'''
|
22
|
+
Internal function and please call _read_ref_value instead of it
|
23
|
+
'''
|
24
|
+
#match = re.match(r'ASPath.*\/(.*)', value)
|
25
|
+
match = re.match(r'ASPath:(.*)', value)
|
26
|
+
if (match):
|
27
|
+
return match.group(1)
|
28
|
+
return value
|
29
|
+
|
30
|
+
def read_value(self, parent: ET.Element, name: str) -> str:
|
31
|
+
tag = parent.find(".//d:var[@name='%s']" % name, self.ns)
|
32
|
+
if tag == None:
|
33
|
+
raise KeyError("XPath d:var[@name='%s'] is invalid" % name)
|
34
|
+
if (tag.attrib['type'] == 'INTEGER'):
|
35
|
+
return int(tag.attrib['value'])
|
36
|
+
elif (tag.attrib['type'] == "FLOAT"):
|
37
|
+
return float(tag.attrib['value'])
|
38
|
+
elif (tag.attrib['type'] == 'BOOLEAN'):
|
39
|
+
if (tag.attrib['value'] == 'true'):
|
40
|
+
return True
|
41
|
+
else:
|
42
|
+
return False
|
43
|
+
else:
|
44
|
+
return tag.attrib['value']
|
45
|
+
|
46
|
+
def read_optional_value(self, parent: ET.Element, name: str, default_value = None) -> str:
|
47
|
+
tag = parent.find(".//d:var[@name='%s']" % name, self.ns)
|
48
|
+
if tag is None:
|
49
|
+
return default_value
|
50
|
+
if ('value' not in tag.attrib):
|
51
|
+
return default_value
|
52
|
+
return tag.attrib['value']
|
53
|
+
|
54
|
+
def find_choice_tag(self, parent: ET.Element, name: str) -> ET.Element:
|
55
|
+
return parent.find(".//d:chc[@name='%s']" % name, self.ns)
|
56
|
+
|
57
|
+
def read_choice_value(self, parent: ET.Element, name: str) -> str:
|
58
|
+
tag = self.find_choice_tag(parent, name)
|
59
|
+
return tag.attrib['value']
|
60
|
+
|
61
|
+
def read_ref_value(self, parent: ET.Element, name: str) -> str:
|
62
|
+
tag = parent.find(".//d:ref[@name='%s']" % name, self.ns)
|
63
|
+
return self.read_ref_raw_value(tag.attrib['value'])
|
64
|
+
|
65
|
+
def read_optional_ref_value(self, parent: ET.Element, name: str) -> str:
|
66
|
+
tag = parent.find(".//d:ref[@name='%s']" % name, self.ns)
|
67
|
+
enable = self.read_attrib(tag, 'ENABLE')
|
68
|
+
if (enable == 'false'):
|
69
|
+
return ""
|
70
|
+
return self.read_ref_raw_value(tag.attrib['value'])
|
71
|
+
|
72
|
+
def read_ref_value_list(self, parent: ET.Element, name: str) -> List[str]:
|
73
|
+
ref_value_list = []
|
74
|
+
for tag in parent.findall(".//d:lst[@name='%s']/d:ref" % name, self.ns):
|
75
|
+
ref_value_list.append(
|
76
|
+
self.read_ref_raw_value(tag.attrib['value']))
|
77
|
+
return ref_value_list
|
78
|
+
|
79
|
+
def find_ctr_tag_list(self, parent: ET.Element, name: str) -> List[ET.Element]:
|
80
|
+
return parent.findall(".//d:lst[@name='%s']/d:ctr" % name, self.ns)
|
81
|
+
|
82
|
+
def find_chc_tag_list(self, parent: ET.Element, name: str) -> List[ET.Element]:
|
83
|
+
return parent.findall(".//d:lst[@name='%s']/d:chc" % name, self.ns)
|
84
|
+
|
85
|
+
def find_ctr_tag(self, parent: ET.Element, name: str) -> ET.Element:
|
86
|
+
'''
|
87
|
+
Read the child ctr tag.
|
88
|
+
'''
|
89
|
+
tag = parent.find(".//d:ctr[@name='%s']" % name, self.ns)
|
90
|
+
if tag is None:
|
91
|
+
return None
|
92
|
+
enable = self.read_attrib(tag, 'ENABLE')
|
93
|
+
# ctr has the value if
|
94
|
+
# 1. enable attribute do not exist
|
95
|
+
# 2. enable attribute is not false
|
96
|
+
if enable is not None and enable == "false":
|
97
|
+
return None
|
98
|
+
return tag
|
99
|
+
|
100
|
+
def create_ctr_tag(self, name: str, type: str)-> ET.Element:
|
101
|
+
ctr_tag = ET.Element("d:ctr")
|
102
|
+
ctr_tag.attrib['name'] = name
|
103
|
+
ctr_tag.attrib['type'] = type
|
104
|
+
return ctr_tag
|
105
|
+
|
106
|
+
def create_ref_tag(self, name:str, type: str, value = "")-> ET.Element:
|
107
|
+
ref_tag = ET.Element("d:ref")
|
108
|
+
ref_tag.attrib['name'] = name
|
109
|
+
ref_tag.attrib['type'] = type
|
110
|
+
if (value != ""):
|
111
|
+
ref_tag.attrib['value'] = "ASPath:%s" % value
|
112
|
+
return ref_tag
|
113
|
+
|
114
|
+
def create_choice_tag(self, name:str, type:str, value: str)-> ET.Element:
|
115
|
+
choice_tag = ET.Element("d:chc")
|
116
|
+
choice_tag.attrib['name'] = name
|
117
|
+
choice_tag.attrib['type'] = type
|
118
|
+
choice_tag.attrib['value'] = value
|
119
|
+
return choice_tag
|
120
|
+
|
121
|
+
def create_attrib_tag(self, name:str, value: str) -> ET.Element:
|
122
|
+
attrib_tag = ET.Element("a:a")
|
123
|
+
attrib_tag.attrib['name'] = name
|
124
|
+
attrib_tag.attrib['value'] = value
|
125
|
+
return attrib_tag
|
126
|
+
|
127
|
+
def create_ref_lst_tag(self, name:str, type:str = "", ref_list: List[str] = []) -> ET.Element:
|
128
|
+
lst_tag = ET.Element("d:lst")
|
129
|
+
lst_tag.attrib['name'] = name
|
130
|
+
for ref in ref_list:
|
131
|
+
ref_tag = ET.Element("d:ref")
|
132
|
+
ref_tag.attrib['type'] = type
|
133
|
+
ref_tag.attrib['value'] = "ASPath:%s" % ref
|
134
|
+
lst_tag.append(ref_tag)
|
135
|
+
return lst_tag
|
136
|
+
|
137
|
+
def find_lst_tag(self, parent: ET.Element, name: str) -> ET.Element:
|
138
|
+
return parent.find(".//d:lst[@name='%s']" % name, self.ns)
|
139
|
+
|
140
|
+
def read_attrib(self, parent: ET.Element, name: str) -> str:
|
141
|
+
attrib_tag = parent.find(".//a:a[@name='%s']" % name, self.ns)
|
142
|
+
if attrib_tag is None:
|
143
|
+
return None
|
144
|
+
return attrib_tag.attrib['value']
|
145
|
+
|
146
|
+
def _read_namespaces(self, xdm: str):
|
147
|
+
self.ns = dict([node for _, node in ET.iterparse(xdm, events=['start-ns'])])
|
@@ -0,0 +1,43 @@
|
|
1
|
+
from typing import List, Dict
|
2
|
+
import xml.etree.ElementTree as ET
|
3
|
+
import re
|
4
|
+
|
5
|
+
from ..models.abstract import EcucContainer, EcucObject
|
6
|
+
from ..models.eb_doc import EBModel
|
7
|
+
from ..models.os_xdm import Os, OsApplication, OsCounter, OsResource, OsTask, OsIsr
|
8
|
+
from .eb_parser import EBModelParser
|
9
|
+
|
10
|
+
class OsXdmParser(EBModelParser):
|
11
|
+
def __init__(self, ) -> None:
|
12
|
+
super().__init__()
|
13
|
+
|
14
|
+
def parse(self, filename: str, doc: EBModel):
|
15
|
+
self._read_namespaces(filename)
|
16
|
+
tree = ET.parse(filename)
|
17
|
+
self.root_tag = tree.getroot()
|
18
|
+
self.validate_root(self.root_tag)
|
19
|
+
|
20
|
+
self.read_os_tasks(doc.getOs())
|
21
|
+
self.read_os_isrs(doc.getOs())
|
22
|
+
|
23
|
+
def read_os_tasks(self, os: Os):
|
24
|
+
for ctr_tag in self.find_ctr_tag_list(self.root_tag, 'OsTask'):
|
25
|
+
os_task = OsTask()
|
26
|
+
os_task.setName(ctr_tag.attrib['name']) \
|
27
|
+
.setOsTaskPriority(self.read_value(ctr_tag, "OsTaskPriority")) \
|
28
|
+
.setOsTaskActivation(self.read_value(ctr_tag, "OsTaskActivation")) \
|
29
|
+
.setOsTaskSchedule(self.read_value(ctr_tag, "OsTaskSchedule")) \
|
30
|
+
.setOsStacksize(self.read_optional_value(ctr_tag, "OsStacksize", 0))
|
31
|
+
os.addOsTask(os_task)
|
32
|
+
|
33
|
+
def read_os_isrs(self, os: Os):
|
34
|
+
for ctr_tag in self.find_ctr_tag_list(self.root_tag, 'OsIsr'):
|
35
|
+
os_isr = OsIsr()
|
36
|
+
os_isr.setName(ctr_tag.attrib['name']) \
|
37
|
+
.setOsIsrCategory(self.read_value(ctr_tag, "OsIsrCategory")) \
|
38
|
+
.setOsIsrPeriod(self.read_optional_value(ctr_tag, "OsIsrPeriod", 0.0)) \
|
39
|
+
.setOsStacksize(self.read_value(ctr_tag, "OsStacksize")) \
|
40
|
+
.setOsIsrPriority(self.read_optional_value(ctr_tag, "OsIsrPriority"))
|
41
|
+
|
42
|
+
os.addOsIsr(os_isr)
|
43
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
from .excel_reporter.os_xdm import *
|
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import logging
|
2
|
+
from openpyxl import Workbook
|
3
|
+
from openpyxl.worksheet.worksheet import Worksheet
|
4
|
+
|
5
|
+
class ExcelReporter:
|
6
|
+
def __init__(self) -> None:
|
7
|
+
self.wb = Workbook()
|
8
|
+
self._logger = logging.getLogger()
|
9
|
+
|
10
|
+
def write_revision(self):
|
11
|
+
sheet = self.wb['Sheet']
|
12
|
+
sheet.title = "History"
|
13
|
+
|
14
|
+
title_rows = ["When", "Who", "Version", "History"]
|
15
|
+
self.write_title_row(sheet, title_rows)
|
16
|
+
|
17
|
+
def auto_width(self, worksheet: Worksheet):
|
18
|
+
dims = {}
|
19
|
+
for row in worksheet.rows:
|
20
|
+
for cell in row:
|
21
|
+
if cell.value:
|
22
|
+
dims[cell.column_letter] = max((dims.get(cell.column_letter, 0), len(str(cell.value))))
|
23
|
+
|
24
|
+
for col, value in dims.items():
|
25
|
+
worksheet.column_dimensions[col].width = (value + 2) + 2
|
26
|
+
|
27
|
+
def write_title_row(self, sheet: Worksheet, title_row):
|
28
|
+
for idx in range(0, len(title_row)):
|
29
|
+
cell = sheet.cell(row=1, column=idx + 1)
|
30
|
+
cell.value = title_row[idx]
|
31
|
+
|
32
|
+
def write_cell(self, sheet, row, column, value, format = None):
|
33
|
+
cell = sheet.cell(row = row, column=column)
|
34
|
+
cell.value = value
|
35
|
+
if (format != None):
|
36
|
+
if ('alignment' in format):
|
37
|
+
cell.alignment = format['alignment']
|
38
|
+
if ('number_format' in format):
|
39
|
+
cell.number_format = format['number_format']
|
40
|
+
|
41
|
+
def save(self, name: str):
|
42
|
+
self.wb.save(name)
|
43
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
from ...models.eb_doc import EBModel
|
2
|
+
from .abstract import ExcelReporter
|
3
|
+
|
4
|
+
class OsXdmXlsWriter(ExcelReporter):
|
5
|
+
def __init__(self) -> None:
|
6
|
+
super().__init__()
|
7
|
+
|
8
|
+
def write_os_tasks(self, doc: EBModel):
|
9
|
+
sheet = self.wb.create_sheet("OsTask", 0)
|
10
|
+
|
11
|
+
title_row = ["Name", "OsTaskActivation", "OsTaskPriority", "OsTaskSchedule", "OsStacksize"]
|
12
|
+
self.write_title_row(sheet, title_row)
|
13
|
+
|
14
|
+
row = 2
|
15
|
+
for os_task in doc.getOs().getOsTaskList():
|
16
|
+
self.write_cell(sheet, row, 1, os_task.getName())
|
17
|
+
self.write_cell(sheet, row, 2, os_task.getOsTaskActivation())
|
18
|
+
self.write_cell(sheet, row, 3, os_task.getOsTaskPriority())
|
19
|
+
self.write_cell(sheet, row, 4, os_task.getOsTaskSchedule())
|
20
|
+
self.write_cell(sheet, row, 5, os_task.getOsStacksize())
|
21
|
+
row += 1
|
22
|
+
|
23
|
+
self.auto_width(sheet)
|
24
|
+
|
25
|
+
def write_os_isrs(self, doc: EBModel):
|
26
|
+
sheet = self.wb.create_sheet("OsIsr", 0)
|
27
|
+
|
28
|
+
title_row = ["Name", "OsIsrCategory", "OsStacksize"]
|
29
|
+
self.write_title_row(sheet, title_row)
|
30
|
+
|
31
|
+
row = 2
|
32
|
+
for os_isr in doc.getOs().getOsIsrList():
|
33
|
+
self.write_cell(sheet, row, 1, os_isr.getName())
|
34
|
+
self.write_cell(sheet, row, 2, os_isr.getOsIsrCategory())
|
35
|
+
self.write_cell(sheet, row, 3, os_isr.getOsStacksize())
|
36
|
+
row += 1
|
37
|
+
|
38
|
+
self.auto_width(sheet)
|
39
|
+
|
40
|
+
def write(self, filename, doc: EBModel):
|
41
|
+
self.write_os_tasks(doc)
|
42
|
+
self.write_os_isrs(doc)
|
43
|
+
|
44
|
+
self.save(filename)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import logging
|
2
|
+
|
3
|
+
from ..models import OsAutoSARDoc, OsApplication, BswModuleInstance
|
4
|
+
|
5
|
+
class OsApplicationMarkdownWriter:
|
6
|
+
def __init__(self) -> None:
|
7
|
+
self._logger = logging.getLogger()
|
8
|
+
|
9
|
+
def _write_line(self, f_in, line: str):
|
10
|
+
f_in.write(line + "\n")
|
11
|
+
|
12
|
+
def _write_instances(self, f_in, os_application: OsApplication):
|
13
|
+
self._write_line(f_in, "|Instance|Instance Type|Component Type|ASIL|Runnable|Task")
|
14
|
+
self._write_line(f_in, "|--|--|--|--|--|--|")
|
15
|
+
for instance in os_application.get_instances():
|
16
|
+
if isinstance(instance, BswModuleInstance):
|
17
|
+
component_type = "BSW Module"
|
18
|
+
else:
|
19
|
+
component_type = "SW Component"
|
20
|
+
if len(instance.get_mappings()) > 0:
|
21
|
+
package = instance.get_mappings()[0].package
|
22
|
+
else:
|
23
|
+
package = ""
|
24
|
+
self._write_line(f_in, "|%s|%s|%s|%s|%s|%s|" % (instance.name, instance.type, component_type , "", package, ""))
|
25
|
+
for mapping in instance.get_mappings():
|
26
|
+
self._write_line(f_in, "|%s|%s|%s|%s|%s|%s|" % ("", "", "", "", mapping.event, mapping.task))
|
27
|
+
|
28
|
+
|
29
|
+
def _write_os_applications(self, f_in, doc: OsAutoSARDoc):
|
30
|
+
self._write_line(f_in, "# OS Application")
|
31
|
+
for os_app in doc.get_os_applications():
|
32
|
+
self._write_line(f_in, "## %s" % os_app.name)
|
33
|
+
self._write_instances(f_in, os_app)
|
34
|
+
|
35
|
+
|
36
|
+
def write(self, filename: str, doc: OsAutoSARDoc):
|
37
|
+
with open(filename, 'w') as f_in:
|
38
|
+
self._write_os_applications(f_in, doc)
|
39
|
+
|
40
|
+
|
File without changes
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import pytest
|
2
|
+
from ...models.eb_doc import EBModel
|
3
|
+
|
4
|
+
class TestEBModel:
|
5
|
+
|
6
|
+
def test_ebmodel_singleton_exception(self):
|
7
|
+
EBModel.getInstance()
|
8
|
+
with pytest.raises(Exception) as err:
|
9
|
+
EBModel()
|
10
|
+
assert(str(err.value) == "The EBModel is singleton!")
|
11
|
+
|
12
|
+
def test_cannot_find_element(self):
|
13
|
+
document = EBModel.getInstance()
|
14
|
+
assert(document.find("/os/os") == None)
|
15
|
+
|
16
|
+
def test_ebmodel(self):
|
17
|
+
document = EBModel.getInstance()
|
18
|
+
assert (isinstance(document, EBModel))
|
19
|
+
assert (isinstance(document, EBModel))
|
20
|
+
assert (document.getFullName() == "")
|
21
|
+
|
22
|
+
def test_ebmodel_get_os(self):
|
23
|
+
document = EBModel.getInstance()
|
24
|
+
os = document.getOs()
|
25
|
+
assert (os.getFullName() == "/Os/Os")
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
from ...models.eb_doc import EBModel
|
3
|
+
from ...models.abstract import EcucContainer, EcucObject
|
4
|
+
|
5
|
+
class TestEcucContainer:
|
6
|
+
|
7
|
+
def test_create_container(self):
|
8
|
+
document = EBModel.getInstance()
|
9
|
+
os_container = EcucContainer(document, "Os")
|
10
|
+
|
11
|
+
assert (os_container.getFullName() == "/Os")
|
12
|
+
assert (os_container.getParent() == document)
|
13
|
+
assert (os_container.getName() == "Os")
|
14
|
+
|
15
|
+
container = document.find("/Os")
|
16
|
+
|
17
|
+
assert (container.getFullName() == "/Os")
|
18
|
+
assert (container.getParent() == document)
|
19
|
+
assert (container.getName() == "Os")
|
20
|
+
|
21
|
+
assert(isinstance(container, EcucContainer))
|
22
|
+
assert(isinstance(container, EcucObject))
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 melodypapa
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,62 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: py-eb-model
|
3
|
+
Version: 0.8.0
|
4
|
+
Summary: The parser for EB XDM file
|
5
|
+
Home-page:
|
6
|
+
Author: melodypapa
|
7
|
+
Author-email: melodypapa@outlook.com
|
8
|
+
License: proprietary
|
9
|
+
Keywords: EB Tresos XDM
|
10
|
+
Classifier: Development Status :: 1 - Planning
|
11
|
+
Classifier: Environment :: Console
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
14
|
+
Classifier: Operating System :: OS Independent
|
15
|
+
Description-Content-Type: text/markdown
|
16
|
+
License-File: LICENSE
|
17
|
+
Requires-Dist: openpyxl
|
18
|
+
Provides-Extra: pytest
|
19
|
+
Requires-Dist: pytest-cov ; extra == 'pytest'
|
20
|
+
|
21
|
+
# 1. py-eb-model
|
22
|
+
|
23
|
+
1. The python parser engine for EB Tresos Xdm file.
|
24
|
+
2. To support EB Tresos data model with python.
|
25
|
+
|
26
|
+
# 2. How to create the distribution and upload to pypi
|
27
|
+
|
28
|
+
1. Run `python setup.py bdist_wheel` to generate distribution
|
29
|
+
2. Run `twine check dist/*` to check the validation of distribution
|
30
|
+
3. Run `twine upload dist/*` to upload to pypi repository
|
31
|
+
4. Check the website https://pypi.org/project/armodel/ to find out it works or not
|
32
|
+
|
33
|
+
And more details can be found at https://packaging.python.org/
|
34
|
+
|
35
|
+
# 3. CLI
|
36
|
+
|
37
|
+
## 3.1. os-task-xlsx
|
38
|
+
|
39
|
+
Extract the Os Task information from os.xdm and then report all to Excel file.
|
40
|
+
|
41
|
+
```bash
|
42
|
+
os-xdm-xlsx data/Os.xdm data/Os.xlsx
|
43
|
+
```
|
44
|
+
|
45
|
+
**Result:**
|
46
|
+
|
47
|
+
1. OsIsrs
|
48
|
+
|
49
|
+

|
50
|
+
|
51
|
+
2. OsTasks
|
52
|
+
|
53
|
+

|
54
|
+
|
55
|
+
|
56
|
+
# 4. Change History
|
57
|
+
|
58
|
+
**Version 1.0.0**
|
59
|
+
|
60
|
+
1. Create the basic model for EB xdm. (Issue #1)
|
61
|
+
2. Support to extract the Os Tasks/Isrs from EB xdm and store them in the excel files. (Issue #1)
|
62
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
eb_model/__init__.py,sha256=u3VUin2V_1eExLd9NIpw_LGHIAwaG2vEoyhssZurrvM,69
|
2
|
+
eb_model/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
eb_model/cli/os_xdm_2_xls_cli.py,sha256=BzeFhyWHbG57qieDNESaXYggszHSy17uwCeXvEfrbCQ,1629
|
4
|
+
eb_model/models/__init__.py,sha256=_WDgFMwl8w3WnI4ZpjHXMdJVdmqPRpwJ8GLMb4_RGk0,71
|
5
|
+
eb_model/models/abstract.py,sha256=JS_aVD3vPWbYTTpPVo7POilqnXVixVCqbdbMel8Rt7s,1901
|
6
|
+
eb_model/models/eb_doc.py,sha256=5SbUrleAKPQaHSoOlvHwVxpKLdxVlksB4lxXTsKhvro,1296
|
7
|
+
eb_model/models/os_xdm.py,sha256=8Zbl4zPvX4V5cemwVej3QlIe7xTw61d6shOR0jWHU58,6274
|
8
|
+
eb_model/parser/__init__.py,sha256=5qHXKEfEMcE0WvvinJQu_21bNzWFdXTJxUudy-85DEE,40
|
9
|
+
eb_model/parser/eb_parser.py,sha256=OQ94JBOHuX4FleQDgOpvI-VMU8IsM4S7lz0onmPFro0,5840
|
10
|
+
eb_model/parser/os_xdm_parser.py,sha256=ZzS45j_0R6kj1Og0iXKP2IupwGLkNrbzPhPrqNFRvXs,1834
|
11
|
+
eb_model/reporter/__init__.py,sha256=H8D_23UwJi1Ph6yjBfZhxWVbu9ci5_O4471gqXGiZCM,36
|
12
|
+
eb_model/reporter/markdown.py,sha256=NhcJOFQ_BVbkgGe66uAT7KUPIchWU4kfVMtMLQtbK-w,1647
|
13
|
+
eb_model/reporter/excel_reporter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
|
+
eb_model/reporter/excel_reporter/abstract.py,sha256=BOuLhWwwTwqBzErtmwPrelB1iByMfZP9haFmg9ayFQw,1488
|
15
|
+
eb_model/reporter/excel_reporter/os_xdm.py,sha256=WGMxK0PYxi9J5fUZ-EeiiM8NBpIg2WyxRsrN-gK37YE,1589
|
16
|
+
eb_model/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
|
+
eb_model/tests/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
|
+
eb_model/tests/models/test_eb_model.py,sha256=9CQ503ZaMf3LhBBmw8Yvoa7HUWTBctTsgvrGxKOAKZA,798
|
19
|
+
eb_model/tests/models/test_ecuc_container.py,sha256=lZmtXwPMz9T52WFduTgFy16fO2agjSW-Rl2cVypM86s,722
|
20
|
+
py_eb_model-0.8.0.dist-info/LICENSE,sha256=I52rGS7W1IwAmYCUfqTpDaSHoFAdt7grcNiBhk-Z3eI,1088
|
21
|
+
py_eb_model-0.8.0.dist-info/METADATA,sha256=xmKdk0hpGFM4s8wrqIGyYMgO_uPEtC0AOMnS-ditrxY,1633
|
22
|
+
py_eb_model-0.8.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
23
|
+
py_eb_model-0.8.0.dist-info/entry_points.txt,sha256=KZ8zDEf2EQhJULVtV7pjWHfoNbrohMEE9xhMyRx7oIw,67
|
24
|
+
py_eb_model-0.8.0.dist-info/top_level.txt,sha256=DGBNh6YW_x4RF_UoLKW3cKqb2SLnmfuEIZlkTewR66A,9
|
25
|
+
py_eb_model-0.8.0.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
eb_model
|