Minor fixes in extract_modules script 22/82522/6
authorRohan Julka <rohanjulka19@gmail.com>
Fri, 14 Jun 2019 06:47:20 +0000 (12:17 +0530)
committerRohan Julka <rohanjulka19@gmail.com>
Mon, 26 Aug 2019 22:39:28 +0000 (04:09 +0530)
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 <rohanjulka19@gmail.com>
karaf-scripts/src/main/assembly/bin/extract_modules.sh [new file with mode: 0644]
scripts/extract_modules.sh [deleted file]

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 (file)
index 0000000..6b3cfe8
--- /dev/null
@@ -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 (executable)
index 1a59d56..0000000
+++ /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
-