From 7aa6ea6f536fe5c1fcfc381cbe4d12fba7384f5c Mon Sep 17 00:00:00 2001 From: Rohan Julka Date: Fri, 14 Jun 2019 12:17:20 +0530 Subject: [PATCH] Minor fixes in extract_modules script Resolved some fixme's in the script.The yang models which are extracted from the extract_modules script are now organized in different folders on the basis of the ODL project it belongs to. Filtered yang modules not belonging to opendaylight on the basis of namespace field inisde yang modules.The script can now be invoked from any folder. Change-Id: Ie51155f6aa83410a89d2c7b4d00ea5c635065f5c Signed-off-by: Rohan Julka --- .../src/main/assembly/bin/extract_modules.sh | 46 +++++++++++++++++++ scripts/extract_modules.sh | 43 ----------------- 2 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 karaf-scripts/src/main/assembly/bin/extract_modules.sh delete mode 100755 scripts/extract_modules.sh diff --git a/karaf-scripts/src/main/assembly/bin/extract_modules.sh b/karaf-scripts/src/main/assembly/bin/extract_modules.sh new file mode 100644 index 00000000..6b3cfe89 --- /dev/null +++ b/karaf-scripts/src/main/assembly/bin/extract_modules.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# +# Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v1.0 which accompanies this distribution, +# and is available at http://www.eclipse.org/legal/epl-v10.html +# + +# +# This script visits all jars within the OpenDaylight karaf distribution and extracts +# all production YANG modules (as located in META-INF/yang) +# +set -e +BIN_DIR=`dirname $0` +OUTPUT="$BIN_DIR/../opendaylight-models" +INPUT="$BIN_DIR/.." + +# FIXME: also wipe output? +[ -d "$OUTPUT" ] || mkdir "$OUTPUT" + +PROJECTS=`ls -d $INPUT/system/org/opendaylight/*` +for proj in $PROJECTS; do + proj=`basename $proj` + echo "Extracting yang modules from $proj" + JARS=`find $INPUT/system/org/opendaylight/$proj -type f -name '*.jar' | sort -u` + [ -d "$OUTPUT/$proj" ] || mkdir $OUTPUT/$proj + for jar in $JARS; do + unzip -l "$jar" | grep -q -e "\.yang$" && + unzip -q "$jar" 'META-INF/yang/*' -d "$OUTPUT/$proj" + done + if [ -z "$(ls -A $OUTPUT/$proj)" ]; then + rm -rf $OUTPUT/$proj + else + rm -f $OUTPUT/$proj/*.yang + YANGS=`find $OUTPUT/$proj/META-INF/yang/ -type f -name '*.yang'` + for yang in $YANGS; do + name=`basename $yang` + less $yang | grep -q namespace.*opendaylight && + mv $OUTPUT/$proj/META-INF/yang/$name $OUTPUT/$proj && + echo " $name" + done + rm -rf $OUTPUT/$proj/META-INF + fi +done +echo -e "\nYang Modules are extracted to `readlink -f $OUTPUT`" diff --git a/scripts/extract_modules.sh b/scripts/extract_modules.sh deleted file mode 100755 index 1a59d560..00000000 --- a/scripts/extract_modules.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved. -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0 which accompanies this distribution, -# and is available at http://www.eclipse.org/legal/epl-v10.html -# - -# -# This script visits all jars within the OpenDaylight karaf distribution and extracts -# all production YANG modules (as located in META-INF/yang) -# -set -e - -# FIXME: make this tuneable -OUTPUT="opendaylight-models" -INPUT="." - -JARS=`find $INPUT/system/org/opendaylight -type f -name '*.jar' | sort -u` - -# FIXME: also wipe output? -[ -d "$OUTPUT" ] || mkdir "$OUTPUT" -for jar in $JARS; do - artifact=`basename $jar | sed 's/.jar$//'` - echo "Extracting modules from $artifact" - # FIXME: better control over unzip errors - unzip -q "$jar" 'META-INF/yang/*' -d "$artifact" \ - 2>/dev/null || true - - dir="$artifact/META-INF/yang" - if [ -d "$dir" ]; then - for file in `find $dir -type f -name '*.yang'`; do - module=`basename "$file"` - echo -e "\t$module" - # FIXME: better duplicate detection - mv -n "$file" "$OUTPUT" - done - fi - - rm -rf "$artifact" -done - -- 2.36.6