[GRASS-SVN] r49534 - in grass-addons/grass6/general: . g.md5sum

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 5 01:12:42 EST 2011


Author: hamish
Date: 2011-12-04 22:12:42 -0800 (Sun, 04 Dec 2011)
New Revision: 49534

Added:
   grass-addons/grass6/general/g.md5sum/
   grass-addons/grass6/general/g.md5sum/Makefile
   grass-addons/grass6/general/g.md5sum/description.html
   grass-addons/grass6/general/g.md5sum/g.md5sum
Log:
add g.md5sum module: create a hash for a map (grass test suite)

Copied: grass-addons/grass6/general/g.md5sum/Makefile (from rev 49520, grass-addons/grass6/general/g.region.point/Makefile)
===================================================================
--- grass-addons/grass6/general/g.md5sum/Makefile	                        (rev 0)
+++ grass-addons/grass6/general/g.md5sum/Makefile	2011-12-05 06:12:42 UTC (rev 49534)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = g.md5sum
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Copied: grass-addons/grass6/general/g.md5sum/description.html (from rev 49520, grass-addons/grass6/general/g.region.point/description.html)
===================================================================
--- grass-addons/grass6/general/g.md5sum/description.html	                        (rev 0)
+++ grass-addons/grass6/general/g.md5sum/description.html	2011-12-05 06:12:42 UTC (rev 49534)
@@ -0,0 +1,38 @@
+<h2>DESCRIPTION</h2>
+
+<em>g.md5sum</em> is a utility script that creates a checksum hash for
+a given raster, vector, raster3d map, or a database which is connected
+to a vector map.
+<p>
+This module is intended to be used as part of the <i>GRASS Test Suite</i>
+to ensure that code changes do not alter module output unexpectedly.
+
+
+<h2>NOTES</h2>
+
+The operation is performed by exporting the map with the appropriate
+<em>*.out.ascii</em> module and piping the result into the <tt>md5sum</tt>
+program, which must be installed. Databases connected to vector maps
+also have their table column defintion included as part of the hash.
+
+
+<h2>TODO</h2>
+
+Add a layer= option for type=database?<br>
+More detained description of database columns.
+ (does that matter as long as the stored data is the same? e.g. do we care if the DB backend is different?)
+
+
+<h2>SEE ALSO</h2>
+
+The GRASS test suite. [insert URL here]<br>
+<a href="http://grass.osgeo.org/wiki/Development#QA">GRASS QA wiki</a>
+
+
+<h2>AUTHOR</h2>
+
+Hamish Bowman, Dunedin, New Zealand
+<br>
+
+<p>
+<i>Last changed: $Date$</i>

Added: grass-addons/grass6/general/g.md5sum/g.md5sum
===================================================================
--- grass-addons/grass6/general/g.md5sum/g.md5sum	                        (rev 0)
+++ grass-addons/grass6/general/g.md5sum/g.md5sum	2011-12-05 06:12:42 UTC (rev 49534)
@@ -0,0 +1,130 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       g.md5sum
+# AUTHOR(S):    M. Hamish Bowman, Dunedin, New Zealand
+# PURPOSE:      Creates a hash sum for a given map.
+# COPYRIGHT:    (c) 2011 Hamish Bowman, and the GRASS Development Team
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+############################################################################
+# Output precision should be no more than %.16g, to allow for a little
+#  inter-platform slop suggest to use %.14g for doubles and %.6g for floats.
+# Lat/lon coord output needs to export to at least %.9f.
+# The *.out.ascii modules may export as %.*f, but that may change to %.*g.
+
+
+#%Module
+#% description: Creates a hash sum for a given map.
+#% keywords: general
+#%End
+#%Option
+#% key: map
+#% type: string
+#% required: yes
+#% key_desc: name
+#% description: Name of map
+#%End
+#%Option
+#% key: type
+#% type: string
+#% required: yes
+#% options: raster,vector,raster3d,database
+#% answer: raster
+#% key_desc: datatype
+#% description: Data type
+#%End
+
+if [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+fi
+
+#### check if we have md5sum
+if [ ! -x "`which md5sum`" ] ; then
+    g.message -e  "md5sum required, please install it first"
+    exit 1
+fi
+
+if [ "$GIS_OPT_TYPE" = "raster" ] ; then
+    # check if it exists
+    eval `g.findfile element=cell file="$GIS_OPT_MAP"`
+    if [ -z "$name" ] ; then
+	g.message -e  "Raster map <$GIS_OPT_MAP> not found."
+	exit 1
+    fi
+
+    eval `r.info -t map="$GIS_OPT_MAP"`
+    if [ "$datatype" = "CELL" ] ; then
+	DP=0
+    elif [ "$datatype" = "FCELL" ] ; then
+	DP=6
+    elif [ "$datatype" = "DCELL" ] ; then
+	DP=14
+    fi
+
+    r.out.ascii input="$GIS_OPT_MAP" output=- dp="$DP" | \
+	md5sum | cut -f1 -d' '
+fi
+
+
+if [ "$GIS_OPT_TYPE" = "vector" ] ; then
+   # check if it exists
+    eval `g.findfile element=vector file="$GIS_OPT_MAP"`
+    if [ ! "$file" ] ; then
+	g.message -e "Vector map <$GIS_OPT_MAP> not found"
+	exit 1
+    fi
+
+    v.out.ascii input="$GIS_OPT_MAP" output=- format=standard | \
+	md5sum | cut -f1 -d' '
+fi
+
+
+if [ "$GIS_OPT_TYPE" = "raster3d" ] ; then
+    # check if it exists
+    eval `g.findfile element=grid3 file="$GIS_OPT_MAP"`
+    if [ -z "$name" ] ; then
+	g.message -e  "3D raster map <$GIS_OPT_MAP> not found."
+	exit 1
+    fi
+
+    eval `r3.info -t map="$GIS_OPT_MAP"`
+    if [ "$datatype" = "float" ] ; then
+	DP=6
+    elif [ "$datatype" = "double" ] ; then
+	DP=14
+    fi
+
+    r3.out.ascii input="$GIS_OPT_MAP" output=- dp="$DP" | \
+	md5sum | cut -f1 -d' '
+fi
+
+
+if [ "$GIS_OPT_TYPE" = "database" ] ; then
+    # check if it exists
+    v.db.connect -g "$GIS_OPT_MAP" > /dev/null 2> /dev/null
+    if [ $? -ne 0 ] ; then
+	g.message -e "Database <$GIS_OPT_MAP> not found"
+	exit 1
+    fi
+
+    #? add 'db.describe -c' after checking for DB in current mapset?
+    (
+      v.db.connect -c map="$GIS_OPT_MAP"
+      v.db.select map="$GIS_OPT_MAP"
+    ) | md5sum | cut -f1 -d' '
+fi


Property changes on: grass-addons/grass6/general/g.md5sum/g.md5sum
___________________________________________________________________
Added: svn:executable
   + *



More information about the grass-commit mailing list