taste-update-data-view 2.84 KB
Newer Older
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
1 2 3 4
#!/bin/bash

echo TASTE Data View Convertor - From ASN.1 to AADLV2

Maxime Perrotin's avatar
Maxime Perrotin committed
5 6 7 8 9 10
# Initialise the progress bar
myfifo=/tmp/$$$RANDOM
mkfifo $myfifo
tail -f $myfifo | taste-progress-dialog.py &

function quit {
11
    echo '100 Completed' > $myfifo
Maxime Perrotin's avatar
Maxime Perrotin committed
12 13 14 15 16 17
    rm $myfifo
    tailps=$(pstree -p $$ | grep tail | python -c "import sys, re; print re.search(r'tail\((.*)\)', [x for x in sys.stdin][0]).group(1)")
    kill $tailps || xterm -e "echo Internal Error, unable to kill subprocess. Open a terminal and type 'pkill tail' to (hopefully) recover"
    exit $1
}

Maxime Perrotin's avatar
Maxime Perrotin committed
18
if [ -t 1 ] ; then
19 20 21 22 23 24 25 26 27 28 29 30
    COLORON="\e[1m\e[32m"
    REDCOLORON="\e[1m\e[31m"
    COLOROFF="\e[0m"
else
    COLORON=""
    REDCOLORON=""
    COLOROFF=""
fi
INFO="${COLORON}[INFO]${COLOROFF}"
ERROR="${REDCOLORON}[ERROR]${COLOROFF}"


Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
31 32 33 34 35 36 37 38 39
# User may pass several ASN.1 files as parameters
for f in $@
do
    # Ignore taste internal ASN.1 files
    name=$(basename "$f")
    if [ "$name" != taste-types.asn -a "$name" != __ExtraTypes.asn ]
    then
        if [ ! -f "$f" ]
        then
40
            echo -e "${INFO} File not found: ${f}"
Maxime Perrotin's avatar
Maxime Perrotin committed
41
            quit 1
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
42
        else
43
            echo -e "${INFO} Using file: ${f}"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
44 45 46 47 48
            filename=$(readlink -e "$f")
            DATAVIEW+="$filename "
            acnfile=$(readlink -e "${f%.*}.acn")
            if [ -f "$acnfile" ]
            then
49
                echo -e "${INFO} Using ACN file: ${acnfile}"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
50 51 52 53 54 55 56 57 58 59 60
                DATAVIEW+="$acnfile "
            fi
        fi
    fi
done

# If DATAVIEW string is empty, check for DataView.asn in current folder
if [ -z "$(echo -n $DATAVIEW)" ]
then
    if [ -f DataView.asn ]
    then
Maxime Perrotin's avatar
Maxime Perrotin committed
61
        echo -e "${INFO} Using file: DataView.asn"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
62 63
        DATAVIEW=$(readlink -e DataView.asn)
    else
64 65
        >&2 echo -e "${ERROR} No data view found"
        echo -e "${INFO} Usage: taste-update-data-view <set of ASN.1 files>"
Maxime Perrotin's avatar
Maxime Perrotin committed
66
        quit 1
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
67 68 69
    fi
    if [ -f DataView.acn ]
    then
70
        echo -e "${INFO} Using file: DataView.acn"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
71 72 73 74 75 76 77 78 79
        DATAVIEW+=" $(readlink -e DataView.acn)"
    fi
fi

#AADL=${DATAVIEW%.*}.aadl
AADL=DataView.aadl

if [ -f __ExtraTypes.asn ]
then
80
    echo -e "${INFO} Using file: __ExtraTypes.asn"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
81 82 83 84 85
    DATAVIEW+=" $(readlink -e "__ExtraTypes.asn")"
fi

if [ -f __ExtraTypes.acn ]
then
86
    echo -e "${INFO} Using file: __ExtraTypes.acn"
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
87 88 89 90 91
    DATAVIEW+=" $(readlink -e "__ExtraTypes.acn")"
fi

DATAVIEW+=" $(taste-config --prefix)/share/taste-types/taste-types.asn"

92 93
# can asn2aadlPlus with a call to uniq to filter out duplicate outputs
# due to multiple calls to the ASN.1 compiler
94
#asn2aadlPlus $DATAVIEW "$AADL" -aadlv2 2>&1 | uniq >&2
Maxime Perrotin's avatar
Maxime Perrotin committed
95
echo '0-100 Updating data view' > $myfifo
96
asn2aadlPlus $DATAVIEW "$AADL" -aadlv2 2>&1 > >(uniq >&2)
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
97 98 99

if [ "$?" = "1" ]
then
100 101
    >&2 echo -e "${ERROR} Impossible to convert the dataview from ASN.1 to AADL"
    echo -e "${INFO} Command: asn2aadlPlus ${DATAVIEW} ${AADL} -aadlv2"
Maxime Perrotin's avatar
Maxime Perrotin committed
102
    quit 1
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
103
else
104
    echo -e "${INFO} All OK"
Maxime Perrotin's avatar
Maxime Perrotin committed
105
    quit 0
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
106 107
fi