Commit a5ee9a31 authored by yoogx's avatar yoogx

* Example of a visitor using Python API

parent cc84a23d
#! /usr/bin/python
#!/usr/bin/env python
import ocarina;
import sys;
# visitor.py: A simple script to visit all nodes of an AADL instance tree
#
# 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):
"""
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]
features=ocarina.AIN.Features(component)[0];
......@@ -28,11 +66,16 @@ def visitor (component, level):
print ' ' * level,'end of visit of ',component
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.analyze(); # analyze models
err=ocarina.instantiate("rma.erc32"); # instantiate system
err = ocarina.load(repo); # load a file
err = ocarina.analyze(); # analyze models
err = ocarina.instantiate(""); # instantiate system
print '----------------------------------------------------'
print 'Visit AADL Instance tree'
......@@ -43,4 +86,3 @@ def main ():
if __name__ == "__main__":
main ()
sys.exit (0); # exit
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment