1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
$Date: 2013-09-14 07:56:11 +0200 (Sat, 14 Sep 2013) $
NOTE: Please improve this list!
Dear (new) GRASS Developer,
When submitting SHELL scripts to GRASS SVN repositiory,
please take care of following rules:
[ see SUBMITTING for C code hints ]
[ see SUBMITTING_TCLTK for tcl and tk hints ]
[ see SUBMITTING_DOCS for documentation ]
[ see SUBMITTING_PYTHON for Python code hints ]
0. Instructions for the GRASS script parser can be found in the g.parser
module's help page.
http://grass.osgeo.org/grass64/manuals/html64_user/g.parser.html
1. Use the directory structure to place your script appropriately into
the source tree
- scripts go into scripts/
Consider to take a look at [please suggest Shell tutorial].
Also add a Makefile and a description.html file into this directory.
See existing scripts for examples.
2. Add a header section to the script you submit and make sure you include
the copyright. The purpose section is meant to contain a general
overview of the code in the file to assist other programmers that will
need to make changes to your code.
Example (ficticious header for a script called r.myscript) :
#!/bin/sh
############################################################################
#
# MODULE: r.myscript
# AUTHOR(S): Me <email AT some domain>
# PURPOSE: Calculates univariate statistics from a GRASS raster map
# COPYRIGHT: (C) 2005 by the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
#############################################################################
The copyright protects your rights according to GNU General Public
License (www.gnu.org).
You can easily autogenerate the header and parameters from an existing
module using the --script flag. Example:
d.rast --script
Just select an existing module which is close to your application to save
efforts.
3. - deleted.
We don't want the $ ID $ in scripts any more as it
causes problems for the SVN branches.
4. As a general principle, shell variables should almost always be quoted.
Use only secure temp files, see g.tempfile and scripts/* for examples.
5. [This rule is currently under review] If you search for a command in $PATH, do NOT
use the "which" command or the "type -p" command. Both commands are not
supported on all platforms, thus causing problems for some people. As an
alternative, please use code similar to the following shell script snippet
which will perform the same function. In this case, the path of the grass60
command is saved if grass60 is found in $PATH. This won't recognize aliased
command name.
# Search for grass5 command in user's path
for i in `echo $PATH | sed 's/^:/.:/
s/::/:.:/g
s/:$/:./
s/:/ /g'`
do
if [ -f $i/grass5 ] ; then
# Save the path of the grass60 command
GRASS_PATH=$i/grass60
# Use the first one in user's path
break
fi
done
<?>
If you must use "which", use as follows:
# check if we have awk
if [ ! -x "`which awk`" ] ; then
g.message -e "awk required, please install awk or gawk first"
exit 1
fi
</?>
6. Add a test to check if the user is in GRASS before starting main part
of script. Result of running the script is unpredicable otherwise.
if [ -z "$GISBASE" ] ; then
echo "You must be in GRASS GIS to run this program." 1>&2
exit 1
fi
This is the only case, where g.message module (see below) can not be used.
In all other cases, you should prefer it's usage over the 'echo' command.
7. Create and use secure temporary files and directories. Use the g.tempfile
module to do this. e.g.
# setup temporary file
TMP="`g.tempfile pid=$$`"
if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
g.message -e "unable to create temporary files"
exit 1
fi
For temportary directories remove the newly created file and mkdir using
the same name. Beware of commands like "rm -f ${TMP}*" as this becomes
"rm -f *" if $TMP is unset (hence the test above).
8. Testing the existence of variables. For portability, use
if [ -z "$VARIABLE" ] ; then
instead of
if [ "$VARIABLE" = "" ] ; then
and
if [ -n "$VARIABLE" ] ; then
instead of
if [ "$VARIABLE" != "" ] ; then
9. Internationalization proofing Awk: In some areas (e.g. some European
countries) the decimal place is held with a comma instead of a dot.
When scanning variables awk doesn't understand this, so scripts need to
temporarily discard locale settings before calling awk.
# set environment so that awk works properly in all languages
unset LC_ALL
LC_NUMERIC=C
export LC_NUMERIC
awk '{print $1}'
10. Use g.findfile when there is a need to test if a map exists.
# test for input raster map
g.findfile element=cell file="$INPUT" > /dev/null
if [ $? -eq 0 ] ; then
g.message -e "Raster map <$GIS_OPT_MAP> not found in mapset search path"
exit 1
fi
# test for input vector map
eval `g.findfile element=vector file=$GIS_OPT_MAP`
if [ ! "$file" ] ; then
g.message -e "Vector map <$GIS_OPT_MAP> not found in mapset search path"
exit 1
fi
... and so forth. See 'g.manual g.findfile' for details.
11. For any informational output, use the g.message modul. This module should
be also used for error messages and warnings. You can also use it for
debugging purposes.
#normal message:
g.message "Done"
# warning:
g.message -w "No input values found, using default values"
# error:
g.message -e "No map found, exiting."
# debug output (use g.gisenv to enable/disable)
g.message -d "Our calculated value is: $value"
Try to omit any usage of the 'echo' command for informational output.
12. For consistency, use README rather than README.txt for any README files.
13. Be sure to develop on top of the LATEST GRASS code (which is in SVN).
You can re-check before submission with 'cvs diff':
Be sure to create unified ("diff -u") format. "Plain"
diffs (the default format) are risky, because they will apply without
warning to code which has been substantially changed; they are also
harder to read than unified.
Such diffs should be made from the top-level directory, e.g.
"cvs diff display/d.vect/main.c"; that way, the diff will
include the pathname rather than just "main.c".
14. For portability, scripts must work on any POSIX compliant shell, and
therefore may not include any Bashisms. Test with ash for errors:
ash -n scriptname
15. When submitting new files to the repository set SVN properties,
usually for directory
svn:ignore : *.tmp.html
or e.g. for script file
svn:executable : *
svn:mime-type : text/x-sh
svn:keywords : Author Date Id
svn:eol-style : native
See
http://svnbook.red-bean.com/en/1.4/svn.advanced.props.html
16. Tell the other developers about the new code using the following e-mail:
grass-dev@lists.osgeo.org
To subscribe to this mailing list, see
http://lists.osgeo.org/mailman/listinfo/grass-dev
17. In case of questions feel free to contact the developers at the above
mailing list.
http://grass.osgeo.org/devel/index.php#submission
...
[please add further hints if required]
|