Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
Ocarina
Commits
a5ee9a31
Commit
a5ee9a31
authored
Jul 18, 2015
by
yoogx
Browse files
* Example of a visitor using Python API
parent
cc84a23d
Changes
1
Show whitespace changes
Inline
Side-by-side
resources/runtime/python/test/visitor.py
View file @
a5ee9a31
#!
/usr/bin/python
#!/usr/bin/
env
python
import
ocarina
;
# visitor.py: A simple script to visit all nodes of an AADL instance tree
import
sys
;
#
# Note: this scripts require the docopt package
"""visitor.py: A simple script to visit all nodes of an AADL instance tree
Usage: visitor.py FILE
visitor.py ( -h | --help )
visitor.py --version
Arguments:
FILE AADL file to process
Options:
-h, --help Help information
--version Version information
"""
from
docopt
import
docopt
import
sys
###################################
args
=
sys
.
argv
[
1
:]
# XXX: we have to do a back-up of the command-line arguments prior to
# importing Ocarina, as its initialization phase will erase sys.argv
# To be investigated, see github issue #45 for details
###################################
import
ocarina
def
visitor
(
component
,
level
):
def
visitor
(
component
,
level
):
"""
This function visits an AADL component, and prints information
about its features, subcomponents and properties.
Args:
component (str): the NodeId of the component
level (int): indentation level
"""
print
' '
*
level
,
'Visiting '
,
ocarina
.
getInstanceName
(
component
)[
0
]
print
' '
*
level
,
'Visiting '
,
ocarina
.
getInstanceName
(
component
)[
0
]
features
=
ocarina
.
AIN
.
Features
(
component
)[
0
];
features
=
ocarina
.
AIN
.
Features
(
component
)[
0
];
...
@@ -28,11 +66,16 @@ def visitor (component, level):
...
@@ -28,11 +66,16 @@ def visitor (component, level):
print
' '
*
level
,
'end of visit of '
,
component
print
' '
*
level
,
'end of visit of '
,
component
def
main
():
def
main
():
'''Test function'''
# read command line arguments
arguments
=
docopt
(
__doc__
,
args
,
version
=
"visitor.py 0.1"
)
# build the repository path
repo
=
arguments
[
'FILE'
]
err
=
ocarina
.
load
(
"rma.aadl"
);
# load a file
err
=
ocarina
.
load
(
repo
);
# load a file
err
=
ocarina
.
analyze
();
# analyze models
err
=
ocarina
.
analyze
();
# analyze models
err
=
ocarina
.
instantiate
(
"
rma.erc32"
);
# instantiate system
err
=
ocarina
.
instantiate
(
"
"
);
# instantiate system
print
'----------------------------------------------------'
print
'----------------------------------------------------'
print
'Visit AADL Instance tree'
print
'Visit AADL Instance tree'
...
@@ -43,4 +86,3 @@ def main ():
...
@@ -43,4 +86,3 @@ def main ():
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
main
()
main
()
sys
.
exit
(
0
);
# exit
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment