visitor.py 2.59 KB
Newer Older
1
#!/usr/bin/env python
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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
33
34

def visitor (component, level):
35
36
37
38
39
40
41
42
43
44
    """
    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

    """

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    print ' ' * level,'Visiting ',ocarina.getInstanceName(component)[0]

    features=ocarina.AIN.Features(component)[0];
    if features is not None :
        print ' ' * level,' -> features:',features
        for feature in features :
            print ' ' * level,'   -> ',feature,",",ocarina.getInstanceName(feature)[0]

    properties = ocarina.AIN.Properties(component)[0];
    if properties is not None :
        print ' ' * level,' -> properties:'
        for property in properties:
            print ' ' * level,'   ',ocarina.getPropertyValue(component,property)[0]

    subcomponents=ocarina.AIN.Subcomponents(component)[0];
    if subcomponents is not None :
        print ' ' * level,' -> subcomponents:',subcomponents
        for subcomponent in subcomponents :
            print ' ' * level,'   -> ',subcomponent,",",ocarina.getInstanceName(subcomponent)[0]
            visitor(str(ocarina.AIN.Corresponding_Instance(subcomponent)[0]),level+3)

    print ' ' * level,'end of visit of ',component

def main ():
69
70
71
72
73
74
    # read  command line arguments

    arguments = docopt(__doc__, args, version="visitor.py 0.1")

    # build the repository path
    repo = arguments['FILE']
75

76
77
78
    err = ocarina.load(repo);       # load a file
    err = ocarina.analyze();        # analyze models
    err = ocarina.instantiate("");  # instantiate system
79
80
81
82
83
84
85
86
87
88

    print '----------------------------------------------------'
    print 'Visit AADL Instance tree'
    print '----------------------------------------------------'

    root=ocarina.getRoot()[0]
    visitor(root,0)

if __name__ == "__main__":
    main ()