source: grass-addons/tools/module_key_list.sh

Last change on this file was 50679, checked in by hamish, 13 years ago

fix diff cmd

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:mime-type set to text/x-sh
File size: 3.3 KB
Line 
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
28if [ -z "$GISBASE" ] ; then
29 echo "You must be in GRASS GIS to run this program." 1>&2
30 exit 1
31fi
32
33if [ "$1" != "@ARGS_PARSED@" ] ; then
34 exec g.parser "$0" "$@"
35fi
36
37
38TEMPFILE="`g.tempfile pid=$$`"
39if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
40 g.message -e "Unable to create temporary files"
41 exit 1
42fi
43
44#### check if we have awk
45if [ ! -x "`which xml2`" ] ; then
46 g.message -e "xml2 is required, please install it first"
47 exit 1
48fi
49
50OUTFILE="module_key_list_$GRASS_VERSION.txt"
51
52# check if we will overwrite data
53if [ -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
58fi
59
60BASE_DIR="`pwd`"
61
62cd "$GISBASE"
63
64for 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"
74done
75
76
77# -i is a GNU extension, won't work on a Mac?
78sed -i -e 's/^<?xml .*//' -e 's/^<!DOCTYPE .*//' "$TEMPFILE"
79
80cat << EOF > "$TEMPFILE.header"
81<?xml version="1.0" encoding="ANSI_X3.4-1968"?>
82<!DOCTYPE task SYSTEM "grass-interface.dtd">
83<modules>
84EOF
85
86cat << EOF > "$TEMPFILE.footer"
87</modules>
88EOF
89
90cat "$TEMPFILE.header" "$TEMPFILE" "$TEMPFILE.footer" > "$TEMPFILE.xml"
91
92
93
94cd "$BASE_DIR"
95
96echo "# `g.version`module key list -- `date`" > "$OUTFILE"
97
98xml2 < "$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
105g.message "List written to <$OUTFILE>."
106g.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
113rm -f "$TEMPFILE" "$TEMPFILE.xml" "$TEMPFILE.header" "$TEMPFILE.footer"
114
115exit 0
116
117
118#########################################################################
119### howto get this to work ????
120# see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=506788
121
122BASE="modules/task"
123FIELDS="
124@name
125parameter/@name
126flag/@name
127"
128
129xml2 < "$TEMPFILE.xml" | grep '/@name=' |
130 grep -v '/flag/@name=verbose$\|/flag/@name=quiet' | \
131 2csv -d'|' $BASE $FIELDS | less
Note: See TracBrowser for help on using the repository browser.