| 1 | #!/bin/sh
|
|---|
| 2 |
|
|---|
| 3 | ############################################################################
|
|---|
| 4 | #
|
|---|
| 5 | # MODULE: module_key_list.sh
|
|---|
| 6 | # AUTHOR(S): Hamish Bowman, Dunedin, New Zealand
|
|---|
| 7 | # PURPOSE: make a list of all the module options for later comparison
|
|---|
| 8 | # COPYRIGHT: (C) 2012 GRASS Development Team/hb
|
|---|
| 9 | #
|
|---|
| 10 | # This program is free software; you can redistribute it and/or modify
|
|---|
| 11 | # it under the terms of the GNU General Public License as published by
|
|---|
| 12 | # the Free Software Foundation; either version 2 of the License, or
|
|---|
| 13 | # (at your option) any later version.
|
|---|
| 14 | #
|
|---|
| 15 | # This program is distributed in the hope that it will be useful,
|
|---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 18 | # GNU General Public License for more details.
|
|---|
| 19 | #
|
|---|
| 20 | ############################################################################
|
|---|
| 21 |
|
|---|
| 22 | #%Module
|
|---|
| 23 | #% description: Generates a list of all modules' option and flag names.
|
|---|
| 24 | #% keywords: infrastructure
|
|---|
| 25 | #%End
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | if [ -z "$GISBASE" ] ; then
|
|---|
| 29 | echo "You must be in GRASS GIS to run this program." 1>&2
|
|---|
| 30 | exit 1
|
|---|
| 31 | fi
|
|---|
| 32 |
|
|---|
| 33 | if [ "$1" != "@ARGS_PARSED@" ] ; then
|
|---|
| 34 | exec g.parser "$0" "$@"
|
|---|
| 35 | fi
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | TEMPFILE="`g.tempfile pid=$$`"
|
|---|
| 39 | if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
|
|---|
| 40 | g.message -e "Unable to create temporary files"
|
|---|
| 41 | exit 1
|
|---|
| 42 | fi
|
|---|
| 43 |
|
|---|
| 44 | #### check if we have awk
|
|---|
| 45 | if [ ! -x "`which xml2`" ] ; then
|
|---|
| 46 | g.message -e "xml2 is required, please install it first"
|
|---|
| 47 | exit 1
|
|---|
| 48 | fi
|
|---|
| 49 |
|
|---|
| 50 | OUTFILE="module_key_list_$GRASS_VERSION.txt"
|
|---|
| 51 |
|
|---|
| 52 | # check if we will overwrite data
|
|---|
| 53 | if [ -e "$OUTFILE" ] ; then
|
|---|
| 54 | if [ -z "$GRASS_OVERWRITE" ] || [ "$GRASS_OVERWRITE" -ne 1 ] ; then
|
|---|
| 55 | g.message -e "Output file <$OUTFILE> already exists."
|
|---|
| 56 | exit 1
|
|---|
| 57 | fi
|
|---|
| 58 | fi
|
|---|
| 59 |
|
|---|
| 60 | BASE_DIR="`pwd`"
|
|---|
| 61 |
|
|---|
| 62 | cd "$GISBASE"
|
|---|
| 63 |
|
|---|
| 64 | for MOD in bin/* scripts/* ; do
|
|---|
| 65 | MODULE=`basename "$MOD"`
|
|---|
| 66 | if [ "$MODULE" = "g.parser" ] || \
|
|---|
| 67 | [ "$MODULE" = "r.mapcalc" ] || \
|
|---|
| 68 | [ "$MODULE" = "r3.mapcalc" ] ; then
|
|---|
| 69 | continue
|
|---|
| 70 | fi
|
|---|
| 71 |
|
|---|
| 72 | g.message -v "[$MODULE]"
|
|---|
| 73 | "$MODULE" --interface-description >> "$TEMPFILE"
|
|---|
| 74 | done
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | # -i is a GNU extension, won't work on a Mac?
|
|---|
| 78 | sed -i -e 's/^<?xml .*//' -e 's/^<!DOCTYPE .*//' "$TEMPFILE"
|
|---|
| 79 |
|
|---|
| 80 | cat << EOF > "$TEMPFILE.header"
|
|---|
| 81 | <?xml version="1.0" encoding="ANSI_X3.4-1968"?>
|
|---|
| 82 | <!DOCTYPE task SYSTEM "grass-interface.dtd">
|
|---|
| 83 | <modules>
|
|---|
| 84 | EOF
|
|---|
| 85 |
|
|---|
| 86 | cat << EOF > "$TEMPFILE.footer"
|
|---|
| 87 | </modules>
|
|---|
| 88 | EOF
|
|---|
| 89 |
|
|---|
| 90 | cat "$TEMPFILE.header" "$TEMPFILE" "$TEMPFILE.footer" > "$TEMPFILE.xml"
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | cd "$BASE_DIR"
|
|---|
| 95 |
|
|---|
| 96 | echo "# `g.version`module key list -- `date`" > "$OUTFILE"
|
|---|
| 97 |
|
|---|
| 98 | xml2 < "$TEMPFILE.xml" | grep '/@name=' | \
|
|---|
| 99 | sed -e 's+^/modules/task/++' -e 's+@name=+name=+' \
|
|---|
| 100 | -e 's+^\(name=\)+\n\1+' -e 's/name=//'| \
|
|---|
| 101 | grep -v '^flag/verbose$\|^flag/quiet$' \
|
|---|
| 102 | >> "$OUTFILE"
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 | g.message "List written to <$OUTFILE>."
|
|---|
| 106 | g.message " Next run: diff -U 7 module_key_list_\$OLD.txt module_key_list_\$NEW.txt"
|
|---|
| 107 |
|
|---|
| 108 | ## todo: how to sort per-module params and flags so a re-arrangement of
|
|---|
| 109 | ## order doesn't indicate an interface change?
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | #cleanup
|
|---|
| 113 | rm -f "$TEMPFILE" "$TEMPFILE.xml" "$TEMPFILE.header" "$TEMPFILE.footer"
|
|---|
| 114 |
|
|---|
| 115 | exit 0
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | #########################################################################
|
|---|
| 119 | ### howto get this to work ????
|
|---|
| 120 | # see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=506788
|
|---|
| 121 |
|
|---|
| 122 | BASE="modules/task"
|
|---|
| 123 | FIELDS="
|
|---|
| 124 | @name
|
|---|
| 125 | parameter/@name
|
|---|
| 126 | flag/@name
|
|---|
| 127 | "
|
|---|
| 128 |
|
|---|
| 129 | xml2 < "$TEMPFILE.xml" | grep '/@name=' |
|
|---|
| 130 | grep -v '/flag/@name=verbose$\|/flag/@name=quiet' | \
|
|---|
| 131 | 2csv -d'|' $BASE $FIELDS | less
|
|---|