[GRASS-SVN] r30547 - in grass/trunk/scripts: db.dropcol db.droptable v.db.addtable v.db.univar v.in.garmin v.in.gns v.in.gpsbabel v.univar.sh

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 13 04:01:14 EDT 2008


Author: hamish
Date: 2008-03-13 04:01:14 -0400 (Thu, 13 Mar 2008)
New Revision: 30547

Modified:
   grass/trunk/scripts/db.dropcol/db.dropcol
   grass/trunk/scripts/db.droptable/db.droptable
   grass/trunk/scripts/v.db.addtable/description.html
   grass/trunk/scripts/v.db.addtable/v.db.addtable
   grass/trunk/scripts/v.db.univar/description.html
   grass/trunk/scripts/v.in.garmin/v.in.garmin
   grass/trunk/scripts/v.in.gns/description.html
   grass/trunk/scripts/v.in.gpsbabel/v.in.gpsbabel
   grass/trunk/scripts/v.univar.sh/description.html
Log:
Use 'db.connect -c' to check/set default DB driver settings

Modified: grass/trunk/scripts/db.dropcol/db.dropcol
===================================================================
--- grass/trunk/scripts/db.dropcol/db.dropcol	2008-03-13 07:23:14 UTC (rev 30546)
+++ grass/trunk/scripts/db.dropcol/db.dropcol	2008-03-13 08:01:14 UTC (rev 30547)
@@ -73,15 +73,15 @@
 
 cleanup()
 {
- \rm -f $TMP $TMP.coltypes $TMP.colnames $TMP.coldesc
+ \rm -f "$TMP" "$TMP.coltypes" "$TMP.colnames" "$TMP.coldesc"
 }
 
 # what to do in case of user break:
 exitprocedure()
 {
- g.message -e 'User break!'
- cleanup
- exit 1
+   g.message -e 'User break!'
+   cleanup
+   exit 1
 }
 # shell check for user break (signal list: trap -l)
 trap "exitprocedure" 2 3 15
@@ -90,9 +90,13 @@
 eval `g.gisenv`
 : ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
 
-table=$GIS_OPT_TABLE
-database=`db.connect -p | grep 'database' | cut -d ':' -f2`
-driver=`db.connect -p | grep 'driver' | cut -d ':' -f2`
+table="$GIS_OPT_TABLE"
+
+# check if DB parameters are set, and if not set them.
+db.connect -c
+
+database=`db.connect -p | grep '^database' | cut -d ':' -f2`
+driver=`db.connect -p | grep '^driver' | cut -d ':' -f2`
 # schema needed for PG?
 col="$GIS_OPT_COLUMN"
 

Modified: grass/trunk/scripts/db.droptable/db.droptable
===================================================================
--- grass/trunk/scripts/db.droptable/db.droptable	2008-03-13 07:23:14 UTC (rev 30546)
+++ grass/trunk/scripts/db.droptable/db.droptable	2008-03-13 08:01:14 UTC (rev 30547)
@@ -51,8 +51,8 @@
 # what to do in case of user break:
 exitprocedure()
 {
- g.message -e 'User break!'
- exit 1
+   g.message -e 'User break!'
+   exit 1
 }
 # shell check for user break (signal list: trap -l)
 trap "exitprocedure" 2 3 15
@@ -61,9 +61,13 @@
 eval `g.gisenv`
 : ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
 
-table=$GIS_OPT_TABLE
-database=`db.connect -p | grep 'database' | cut -d ':' -f2`
-driver=`db.connect -p | grep 'driver' | cut -d ':' -f2`
+table="$GIS_OPT_TABLE"
+
+# check if DB parameters are set, and if not set them.
+db.connect -c
+
+database=`db.connect -p | grep '^database' | cut -d ':' -f2`
+driver=`db.connect -p | grep '^driver' | cut -d ':' -f2`
 # schema needed for PG?
 col="$GIS_OPT_COLUMN"
 
@@ -73,10 +77,10 @@
 fi
 
 # check if table exists
-db.describe -c $GIS_OPT_TABLE >/dev/null 2>/dev/null
+db.describe -c "$GIS_OPT_TABLE" >/dev/null 2>/dev/null
 if [ $? -ne 0 ] ; then
-        g.message -e "Table <$table> not found in current mapset"
-        exit 1
+   g.message -e "Table <$table> not found in current mapset"
+   exit 1
 fi
 
 # check if table is used somewhere (connected to vector map)

Modified: grass/trunk/scripts/v.db.addtable/description.html
===================================================================
--- grass/trunk/scripts/v.db.addtable/description.html	2008-03-13 07:23:14 UTC (rev 30546)
+++ grass/trunk/scripts/v.db.addtable/description.html	2008-03-13 08:01:14 UTC (rev 30547)
@@ -50,4 +50,5 @@
 
 Markus Neteler
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>

Modified: grass/trunk/scripts/v.db.addtable/v.db.addtable
===================================================================
--- grass/trunk/scripts/v.db.addtable/v.db.addtable	2008-03-13 07:23:14 UTC (rev 30546)
+++ grass/trunk/scripts/v.db.addtable/v.db.addtable	2008-03-13 08:01:14 UTC (rev 30547)
@@ -113,30 +113,23 @@
 # we use the DB settings of layer 1 to find out default connection
 QUERYLAYER=1
 
+# check if DB parameters are set, and if not set them.
+db.connect -c
+
 #check if anything is connected:
 v.db.connect map="$GIS_OPT_MAP" -g  2> /dev/null | grep '^1 ' > /dev/null
 if [ $? -ne 0 ] ; then
    # nothing defined for layer 1
-   g.message "Creating new DB connection based on default mapset settings..." 
-   database=`db.connect -p | grep database | cut -d':' -f2`
-   if [ $? -ne 0 ] ; then  # this tests the result of cut? what if "(null)"? grep -v '(null)'?
-       g.message -e "An error occured while running db.connect" 
-       exit 1
-   fi
-   driver=`db.connect -p | grep driver | cut -d':' -f2`
-   if [ -z "$driver" ] || [ -z "$database" ] ; then
-      g.message "Setting default database driver to DBF."
-      database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'
-      driver=dbf
-      db.connect driver="$driver" database="$database"
-   fi
+   g.message "Creating new DB connection based on default mapset settings..."
+   database=`db.connect -p | grep '^database' | cut -d':' -f2`
+   driver=`db.connect -p | grep '^driver' | cut -d':' -f2`
 else
    # there is a definition for layer 1, so we check for the user defined layer
    database=`v.db.connect map="$GIS_OPT_MAP" -g | grep -w "$QUERYLAYER" | awk '{print $4}'`
    if [ -z "database" ] ; then
       #nothing on user defined layer, so we use the default mapset settings in this case:
-      database=`db.connect -p | grep database | cut -d':' -f2`
-      driver=`db.connect -p | grep driver | cut -d':' -f2`
+      database=`db.connect -p | grep '^database' | cut -d':' -f2`
+      driver=`db.connect -p | grep '^driver' | cut -d':' -f2`
    else
       driver=`v.db.connect map="$GIS_OPT_MAP" -g | grep -w "$QUERYLAYER" | awk '{print $5}'`
    fi
@@ -172,7 +165,7 @@
        if test ! -d "${LOCATION}/dbf" ; then
           g.message "Creating missing DBF directory in MAPSET <$MAPSET>"
           mkdir -p "${LOCATION}/dbf"
-         db.connect driver=dbf database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'
+          db.connect driver=dbf database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'
        fi
    fi
 

Modified: grass/trunk/scripts/v.db.univar/description.html
===================================================================
--- grass/trunk/scripts/v.db.univar/description.html	2008-03-13 07:23:14 UTC (rev 30546)
+++ grass/trunk/scripts/v.db.univar/description.html	2008-03-13 08:01:14 UTC (rev 30547)
@@ -4,14 +4,15 @@
 <EM><b>v.db.univar</b></EM>  - Calculates basic univariate statistics for numeric
 attributes in a data table. It will calculate minimum, maximum, range, mean,
 standard deviation, variance, coefficient of variation, quartiles, median, and
-90th percentile. It uses db.select to create list values for statistical calculations.
+90th percentile.
+It uses <em>db.select</em> to create list values for statistical calculations.
 
 <EM>(GRASS Shell Script)</EM>
 
 <H2>NOTES</H2>
 
-Unless the database and driver are specified, it default the values set in
-<em>db.connect</em>.
+If the database and driver are not specified, the default values set in
+<em>db.connect</em> will be used.
 
 <H2>EXAMPLE</H2>
 
@@ -36,6 +37,6 @@
 <H2>AUTHOR</H2>
  Michael Barton, Arizona State University
 <p>
-and authors of r.univar.sh 
+and authors of <em>r.univar.sh</em>
 <p>
 <i>Last changed: $Date$</i>

Modified: grass/trunk/scripts/v.in.garmin/v.in.garmin
===================================================================
--- grass/trunk/scripts/v.in.garmin/v.in.garmin	2008-03-13 07:23:14 UTC (rev 30546)
+++ grass/trunk/scripts/v.in.garmin/v.in.garmin	2008-03-13 08:01:14 UTC (rev 30547)
@@ -761,13 +761,8 @@
 	fi
 
 	# create db links if they don't exist
+	db.connect -c
 	DRIVER="`db.connect -p | grep '^driver:' | cut -f2 -d:`"
-	DATABASE="`db.connect -p | grep '^database:' | cut -f2 -d:`"
-	if [ "$DRIVER" = "(null)" ] || [ "$DATABASE" = "(null)" ] ; then
-	    g.message "Setting default database driver to DBF."
-	    db.connect driver=dbf database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'
-	fi
-	DRIVER="`db.connect -p | grep '^driver:' | cut -f2 -d:`"
 	if [ "$DRIVER" = "dbf" ] && [ ! -d "$LOCATION/dbf/" ] ; then
 	    mkdir "$LOCATION/dbf/"
 	fi

Modified: grass/trunk/scripts/v.in.gns/description.html
===================================================================
--- grass/trunk/scripts/v.in.gns/description.html	2008-03-13 07:23:14 UTC (rev 30546)
+++ grass/trunk/scripts/v.in.gns/description.html	2008-03-13 08:01:14 UTC (rev 30547)
@@ -12,7 +12,8 @@
 The current DB connection is used to write the database table.
 <P>
 Generally, column names longer that 10 characters are shortened to
-10 characters to meet the DBF column name restrictions.
+10 characters to meet the DBF column name restrictions. If this is a
+problem consider choosing another database driver with <em>db.connect</em>.
 <P>
 To filter outliers (points outside of a country), the <em>v.select</em>
 module can be used to perform point-in-polygon tests. <em>v.select</em>
@@ -35,4 +36,5 @@
 
 Markus Neteler, <a href=http://mpa.itc.it>MPBA Group, ITC-irst</a>
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>

Modified: grass/trunk/scripts/v.in.gpsbabel/v.in.gpsbabel
===================================================================
--- grass/trunk/scripts/v.in.gpsbabel/v.in.gpsbabel	2008-03-13 07:23:14 UTC (rev 30546)
+++ grass/trunk/scripts/v.in.gpsbabel/v.in.gpsbabel	2008-03-13 08:01:14 UTC (rev 30547)
@@ -625,14 +625,9 @@
 	    exit 1
 	fi
 
-	## create db links if they don't exist  (Markus made it automatic now? MN: yes.)
+	## create db links if they don't exist
+	db.connect -c
 	DRIVER="`db.connect -p | grep '^driver:' | cut -f2 -d:`"
-	DATABASE="`db.connect -p | grep '^database:' | cut -f2 -d:`"
-	if [ "$DRIVER" = "(null)" ] || [ "$DATABASE" = "(null)" ] ; then
-	    g.message "Setting default database driver to DBF."
-	    db.connect driver=dbf database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'
-	fi
-	DRIVER="`db.connect -p | grep '^driver:' | cut -f2 -d:`"
 	if [ "$DRIVER" = "dbf" ] && [ ! -d "$LOCATION/dbf/" ] ; then
 	    mkdir "$LOCATION/dbf/"
 	fi

Modified: grass/trunk/scripts/v.univar.sh/description.html
===================================================================
--- grass/trunk/scripts/v.univar.sh/description.html	2008-03-13 07:23:14 UTC (rev 30546)
+++ grass/trunk/scripts/v.univar.sh/description.html	2008-03-13 08:01:14 UTC (rev 30547)
@@ -1,20 +1,22 @@
 <H2>DESCRIPTION</H2>
 
 
-<EM><b>v.univar.sh</b></EM>  - Calculates basic univariate statistics for numeric
+Calculates basic univariate statistics for numeric
 attributes in a data table. It will calculate minimum, maximum, range, mean,
-standard deviation, variance, coefficient of variation, quartiles, median, and
-90th percentile. It is closely based on r.univar.sh and uses db.select to create
-a list values for statistical calculations. This script could be replaced by
-an updated v.univar.<br>
+standard deviation, variance, coefficient of variation, quartiles, median,
+and 90th percentile. It is closely based on <em>r.univar.sh</em> and uses
+<em>db.select</em> to create a list values for statistical calculations.
+This script could be replaced by an updated <em>v.univar</em>.
+<p>
 
 <EM>(GRASS Shell Script)</EM>
 
 <H2>NOTES</H2>
 
-Unless the database and driver are specified, it default the values set in
-<em>db.connect</em>.
+If the database and driver are not specified, the module will use the default
+values set in <em>db.connect</em>.
 
+
 <H2>EXAMPLE</H2>
 
 <div class="code"><pre>
@@ -39,5 +41,6 @@
 <P> AUTHORS
 v.univar.sh: Michael Barton, Arizona State University
 <p>
-and authors of r.univar.sh 
-<p><i>Last changed: $Date$</i>
+and authors of <em>r.univar.sh</em>
+<p>
+<i>Last changed: $Date$</i>



More information about the grass-commit mailing list