Andrea Campanella | 423962b | 2016-02-26 13:09:22 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # ONOS YANG to XML skeleton convert via pyang |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 7 | . $ONOS_ROOT/tools/build/envDefaults |
| 8 | |
| 9 | aux=/tmp/pyangversion |
| 10 | pyang -v $cmd > $aux |
| 11 | errorstring="Pyang no installed, please download and intall from https://github.com/mbj4668/pyang" |
| 12 | cat $aux |
| 13 | grep -q "pyang: command not found" $aux && echo $errorString && exit 1 |
| 14 | |
| 15 | grep -q "pyang 1" $aux |
| 16 | |
| 17 | if ! [ -e "$1" ]; then |
| 18 | echo "$1 input directory not found" >&2 |
| 19 | exit 1 |
| 20 | fi |
| 21 | if ! [ -d "$1" ]; then |
| 22 | echo "$1 not a directory for output" >&2 |
| 23 | exit 1 |
| 24 | fi |
| 25 | cd $1 |
| 26 | find . -name '*.yang' | while read file; do f=$(basename $file ".yang"); \ |
| 27 | directory=$ONOS_ROOT/drivers/utilities/src/main/resources/${PWD##*/}; \ |
| 28 | if [ ! -d "$directory" ]; then |
| 29 | mkdir $directory; \ |
| 30 | fi |
| 31 | echo $directory/$f.xml |
| 32 | pyang -f sample-xml-skeleton $f.yang > $directory/$f.xml; done |
| 33 | exit 0 |