Patchwork [Documentation,01/14] scripts/output-machine-list: add commands interface

login
register
mail settings
Submitter Mario Domenech Goulart
Date April 30, 2014, 12:56 p.m.
Message ID <1398862609-28655-1-git-send-email-mario@ossystems.com.br>
Download mbox | patch
Permalink /patch/71287/
State Accepted
Delegated to: Otavio Salvador
Headers show

Comments

Mario Domenech Goulart - April 30, 2014, 12:56 p.m.
Now output-machine-list accepts two commands: one to list machine
names (list) and another one to print a formatted table of machines
and their corresponding attributes (tabularize).

The script output is now printed to the standard output.

Signed-off-by: Mario Domenech Goulart <mario@ossystems.com.br>
---
 scripts/output-machine-list |   94 +++++++++++++++++++++++++++++++++----------
 1 file changed, 73 insertions(+), 21 deletions(-)
Daiane Angolini - April 30, 2014, 2:12 p.m.
> Subject: [meta-freescale] [Documentation][PATCH 01/14] scripts/output-
> machine-list: add commands interface
> 
> Now output-machine-list accepts two commands: one to list machine names
> (list) and another one to print a formatted table of machines and their
> corresponding attributes (tabularize).
> 
> The script output is now printed to the standard output.

Thanks a lot, Mario. The patch set is merged.

Daiane

Patch

diff --git a/scripts/output-machine-list b/scripts/output-machine-list
index 0ced9ab..807332a 100755
--- a/scripts/output-machine-list
+++ b/scripts/output-machine-list
@@ -1,31 +1,83 @@ 
 #!/bin/sh
 
+usage() {
+    local exit_code
+    local output
+    [ -n $1 ] && exit_code=$1
+    if [ -n "$exit_code" ] && [ "$exit_code" != "0" ]; then
+        output=2
+    else
+        output=1
+    fi
+    cat <<EOF >&$output
+Usage: `basename $0` <yocto directory> [<command>]
+
+Commands:
+
+tabularize
+   Print tabular data for machines
+
+list
+   List machine names
+
+If <command> is omitted, list is used by default.
+EOF
+    [ -n "$exit_code" ] && exit $exit_code
+}
+
+
+[ -z "$1" ] && usage 1
+
+if [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
+    usage 0
+fi
+
 REPO=$1
+COMMAND=$2
 
 TMP=`mktemp`
 MACHINE_LAYERS="meta-fsl-arm meta-fsl-arm-extra"
-DST=`dirname $0`/../release-notes/source/machine-list.inc
-
-for l in $MACHINE_LAYERS; do
-	MACHINES=`cd $REPO; repo forall $l -c 'find -wholename "*/conf/machine/*.conf" | sed "s,./\(.*\),$REPO_PATH/\1,g"'`
-	for m in $MACHINES; do
-		machine=`basename $m | sed 's,\.conf$,,g'`
-		name=`sed -n 's,#@NAME:\s*\(.*\),\1,p' $REPO/$m`
-		soc=`sed -n 's,#@SOC:\s*\(.*\),\1,p' $REPO/$m`
-
-		printf "%-25s  %-50s  %-12s  %-10s\n" "$machine" "$name" "$soc" "$l" >> $TMP
-	done
-done
-
-cat > $DST <<EOF
-=========================  ==================================================  ============  ==========
-         Machine             Name                                                 SoC          Layer
-=========================  ==================================================  ============  ==========
+
+list_machine_files() {
+    for l in $MACHINE_LAYERS; do
+        cd $REPO; repo forall $l -c 'find -wholename "*/conf/machine/*.conf" | sed "s,./\(.*\),$REPO_PATH/\1,g"'
+    done
+}
+
+list_machines() {
+    for m in `list_machine_files`; do
+        basename $m | sed 's,\.conf$,,g'
+    done | sort
+}
+
+tabularize_machines() {
+    for l in $MACHINE_LAYERS; do
+        MACHINES=`cd $REPO; repo forall $l -c 'find -wholename "*/conf/machine/*.conf" | sed "s,./\(.*\),$REPO_PATH/\1,g"'`
+        for m in $MACHINES; do
+            machine=`basename $m | sed 's,\.conf$,,g'`
+            name=`sed -n 's,#@NAME:\s*\(.*\),\1,p' $REPO/$m`
+            soc=`sed -n 's,#@SOC:\s*\(.*\),\1,p' $REPO/$m`
+
+            printf "%-25s  %-50s  %-20s  %-10s\n" "$machine" "$name" "$soc" "$l" >> $TMP
+        done
+    done
+
+    cat <<EOF
+=========================  ==================================================  ====================  ==========
+         Machine             Name                                                      SoC             Layer
+=========================  ==================================================  ====================  ==========
 EOF
 
-sort -u -k 1 $TMP >> $DST
+    sort -u -k 1 $TMP
 
-cat >> $DST <<EOF
-=========================  ==================================================  ============  ==========
+    cat <<EOF
+=========================  ==================================================  ====================  ==========
 EOF
-rm $TMP
+    rm $TMP
+}
+
+case "$COMMAND" in
+    "tabularize") tabularize_machines ;;
+    "list" | "") list_machines ;;
+    *) echo "Invalid command: $COMMAND" >&2
+esac