Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
Ocarina
Commits
38a0e351
Commit
38a0e351
authored
Apr 29, 2015
by
arnaud
Browse files
Add error management at python level
parent
e4de4fdf
Changes
1
Hide whitespace changes
Inline
Side-by-side
resources/runtime/python/ocarina.py
View file @
38a0e351
...
...
@@ -13,9 +13,16 @@ to load, parse, instantiate AADL models, and to invoke backends.
################################################################################
try
:
import
libocarina_python
;
# Ocarina bindings
import
ocarina_me_aadl_aadl_instances_nodes
as
AIN
;
import
ocarina_me_aadl_aadl_tree_nodes
as
ATN
;
import
libocarina_python
# Ocarina bindings
import
ocarina_me_aadl_aadl_instances_nodes
as
AIN
import
ocarina_me_aadl_aadl_tree_nodes
as
ATN
import
sys
import
StringIO
from
contextlib
import
contextmanager
import
ctypes
import
io
import
os
import
tempfile
except
ImportError
:
pass
...
...
@@ -24,12 +31,12 @@ class Enum(tuple): __getattr__ = tuple.index
################################################################################
def
version
():
'''Print Ocarina version'''
libocarina_python
.
version
()
;
libocarina_python
.
version
()
################################################################################
def
status
():
'''Print Ocarina status'''
libocarina_python
.
status
()
;
libocarina_python
.
status
()
################################################################################
def
reset
():
...
...
@@ -38,7 +45,7 @@ def reset ():
**Note:** this function must be called before processing a new set of
models.'''
libocarina_python
.
reset
()
;
libocarina_python
.
reset
()
################################################################################
def
load
(
filename
):
...
...
@@ -49,15 +56,41 @@ def load (filename):
E.g. to load "foo.aadl":
>>> load("foo.aadl")
;
>>> load("foo.aadl")
'''
libocarina_python
.
load
(
filename
);
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
libocarina_python
.
load
(
filename
)
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
analyze
():
'''Analyze models'''
return
libocarina_python
.
analyze
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
analyze
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
instantiate
(
root_system
):
...
...
@@ -67,10 +100,24 @@ def instantiate (root_system):
:type root_system: string
'''
libocarina_python
.
instantiate
(
root_system
);
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
libocarina_python
.
instantiate
(
root_system
)
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
Backends
=
Enum
([
"polyorb_hi_ada"
,
"polyorb_hi_c"
])
;
Backends
=
Enum
([
"polyorb_hi_ada"
,
"polyorb_hi_c"
])
'''List of supported backends, used by :data:`generate`'''
# Note, this list should match backend names as specified by Ocarina CLI
...
...
@@ -81,30 +128,84 @@ def generate (generator):
For instance, to use the PolyORB-HI/Ada backend, you may use the following
>>> generate (Backends.polyorb_hi_ada)
;
>>> generate (Backends.polyorb_hi_ada)
'''
libocarina_python
.
generate
(
Backends
[
generator
]);
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
libocarina_python
.
generate
(
Backends
[
generator
])
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getPackages
():
'''Return the list of all the packages defined in the current AADL project
'''
return
libocarina_python
.
getPackages
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getPackages
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getImportDeclarations
():
'''Return the list of all the import declaration used in the current AADL project
'''Return the list of all the import declaration used in the
current AADL project
'''
return
libocarina_python
.
getImportDeclarations
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getImportDeclarations
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getAliasDeclarations
():
'''Return the list of all the alias declaration defined in the current AADL project
'''Return the list of all the alias declaration defined in the
current AADL project
'''
return
libocarina_python
.
getAliasDeclarations
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getAliasDeclarations
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
...
...
@@ -116,131 +217,323 @@ def getComponentTypes (category):
For instance, to retrieve all the system types from the current project,
you may use the following
>>> getComponentTypes (System)
;
>>> getComponentTypes (System)
'''
return
libocarina_python
.
getComponentTypes
(
category
);
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getComponentTypes
(
category
)
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getComponentImplementations
(
category
):
'''Return a list of component implementations defined in the current AADL project
'''Return a list of component implementations defined in the
current AADL project
:param category: one of the AADL category defined in the standard
For instance, to retrieve all the system implementations from the
current project,
you may use the following
For instance, to retrieve all the system implementations from the
current project,
you may use the following
>>> getComponentImplementations (System)
;
>>> getComponentImplementations (System)
'''
return
libocarina_python
.
getComponentImplementations
(
category
);
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getComponentImplementations
(
category
)
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getAnnexes
():
'''Return the list of all the annexes defined in the current AADL project
'''
return
libocarina_python
.
getAnnexes
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getAnnexes
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getPrototypes
():
'''Return the list of all the prototypes defined in the current AADL project
'''
return
libocarina_python
.
getPrototypes
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getPrototypes
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getPrototypeBindings
():
'''Return the list of all the prototype bindings defined in the current AADL project
'''Return the list of all the prototype bindings defined in the
current AADL project
'''
return
libocarina_python
.
getPrototypeBindings
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getPrototypeBindings
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getFlowSpecifications
():
'''Return the list of all the flow specification defined in the current AADL project
'''Return the list of all the flow specification defined in the
current AADL project
'''
return
libocarina_python
.
getFlowSpecifications
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getFlowSpecifications
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getFlowImplementations
():
'''Return the list of all the flow implementation defined in the current AADL project
'''Return the list of all the flow implementation defined in the
current AADL project
'''
return
libocarina_python
.
getFlowImplementations
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getFlowImplementations
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getModes
():
'''Return the list of all the modes defined in the current AADL project
'''
return
libocarina_python
.
getModes
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getModes
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getModeTransitions
():
'''Return the list of all the mode transition defined in the current AADL project
'''Return the list of all the mode transition defined in the
current AADL project
'''
return
libocarina_python
.
getModeTransitions
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getModeTransitions
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getInModes
():
'''Return the list of all the in mode used in the current AADL project
'''
return
libocarina_python
.
getInModes
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getInModes
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getPropertySets
():
'''Return the list of all the property set defined in the current AADL project
'''Return the list of all the property set defined in the
current AADL project
'''
return
libocarina_python
.
getPropertySets
();
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getPropertySets
()
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getPropertyTypes
(
propertySetId
):
'''Return the list of all the property types defined in the provided property set
'''Return the list of all the property types defined in the
provided property set
:param propertySetId: the nodeId of the property set in the
current AADL project
to serach in
:param propertySetId: the nodeId of the property set in the
current AADL project
to serach in
For instance, to retrieve all the property types from property
set propertySet,
retrieve its id (propertySetId) and use the following
For instance, to retrieve all the property types from property
set propertySet,
retrieve its id (propertySetId) and use the following
>>> getPropertyTypes (propertySetId)
;
>>> getPropertyTypes (propertySetId)
'''
return
libocarina_python
.
getPropertyTypes
(
propertySetId
);
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getPropertyTypes
(
propertySetId
)
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getPropertyDefinitions
(
propertySetId
):
'''Return the list of all the property declaration defined in the provided property set
'''Return the list of all the property declaration defined in the
provided property set
:param propertySetId: the nodeId of the property set in the
current AADL project
to serach in
:param propertySetId: the nodeId of the property set in the
current AADL project
to serach in
For instance, to retrieve all the property declaration from property set propertySet,
retrieve its id (propertySetId) and use the following
For instance, to retrieve all the property declaration from
property set propertySet, retrieve its id (propertySetId)
and use the following
>>> getPropertyDefinitions (propertySetId)
;
>>> getPropertyDefinitions (propertySetId)
'''
return
libocarina_python
.
getPropertyDefinitions
(
propertySetId
);
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getPropertyDefinitions
(
propertySetId
)
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
def
getPropertyConstants
(
propertySetId
):
'''Return the list of all the constant property defined in the provided property set
'''Return the list of all the constant property defined in the
provided property set
:param propertySetId: the nodeId of the property set in the
current AADL project
to serach in
:param propertySetId: the nodeId of the property set in the
current AADL project
to serach in
For instance, to retrieve all the constant property from property
set propertySet,
retrieve its id (propertySetId) and use the following
For instance, to retrieve all the constant property from property
set propertySet,
retrieve its id (propertySetId) and use the following
>>> getPropertyConstants (propertySetId)
;
>>> getPropertyConstants (propertySetId)
'''
return
libocarina_python
.
getPropertyConstants
(
propertySetId
);
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getPropertyConstants
(
propertySetId
)
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
...
...
@@ -252,9 +545,22 @@ def getInstances (category):
For instance, to retrieve all the system instances from the current project,
you may use the following
>>> getInstances (System)
;
>>> getInstances (System)
'''
return
libocarina_python
.
getInstances
(
category
);
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getInstances
(
category
)
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])
return
[
res
,
info
.
getvalue
().
decode
(
'utf-8'
),
stderrMsg
[
0
]
,
raisedError
]
################################################################################
...
...
@@ -266,9 +572,22 @@ def getComponentName (nodeId):
For instance, to retrieve the name of MyComponent,
retrieve its id (nodeId) and use the following
>>> getComponentName (nodeId)
;
>>> getComponentName (nodeId)
'''
return
libocarina_python
.
getComponentName
(
nodeId
);
info
=
io
.
BytesIO
()
error
=
io
.
BytesIO
()
raisedError
=
[]
res
=
''
with
std_redirector
(
info
,
error
):
try
:
res
=
libocarina_python
.
getComponentName
(
nodeId
)
except
:
raisedError
.
append
(
getErrorMessage
())
stderrMsg
=
sortStderrMessages
(
error
.
getvalue
().
decode
(
'utf-8'
))
if
stderrMsg
[
1
]
!=
[]:
raisedError
.
append
(
stderrMsg
[
1
])