Add module extraction script 32/73532/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Jun 2018 12:11:24 +0000 (14:11 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Jun 2018 13:08:01 +0000 (15:08 +0200)
This is a first, raw, cut at extracting models out an opendaylight
distribution.

Change-Id: I92c03634d660cc56ea20a81104e0bf10addb7526
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
scripts/extract_modules.sh [new file with mode: 0755]

diff --git a/scripts/extract_modules.sh b/scripts/extract_modules.sh
new file mode 100755 (executable)
index 0000000..1a59d56
--- /dev/null
@@ -0,0 +1,43 @@
+#!/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
+