[GRASS-SVN] r38044 - in grass/trunk/scripts: . db.dropcolumn db.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 23 10:35:40 EDT 2009


Author: martinl
Date: 2009-06-23 10:35:39 -0400 (Tue, 23 Jun 2009)
New Revision: 38044

Added:
   grass/trunk/scripts/db.dropcolumn/db.dropcolumn.html
   grass/trunk/scripts/db.dropcolumn/db.dropcolumn.py
Removed:
   grass/trunk/scripts/db.dropcolumn/db.dropcol.html
   grass/trunk/scripts/db.dropcolumn/db.dropcol.py
Modified:
   grass/trunk/scripts/Makefile
   grass/trunk/scripts/db.dropcolumn/Makefile
   grass/trunk/scripts/db.in.ogr/db.in.ogr.py
Log:
db.dropcol renamed to db.dropcolumn (module)


Modified: grass/trunk/scripts/Makefile
===================================================================
--- grass/trunk/scripts/Makefile	2009-06-23 14:14:07 UTC (rev 38043)
+++ grass/trunk/scripts/Makefile	2009-06-23 14:35:39 UTC (rev 38044)
@@ -6,7 +6,7 @@
 	d.rast.edit \
 	d.rast.leg \
 	d.shadedmap \
-	db.dropcol \
+	db.dropcolumn \
 	db.droptable \
 	db.in.ogr \
 	db.out.ogr \

Modified: grass/trunk/scripts/db.dropcolumn/Makefile
===================================================================
--- grass/trunk/scripts/db.dropcolumn/Makefile	2009-06-23 14:14:07 UTC (rev 38043)
+++ grass/trunk/scripts/db.dropcolumn/Makefile	2009-06-23 14:35:39 UTC (rev 38044)
@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-PGM = db.dropcol
+PGM = db.dropcolumn
 
 include $(MODULE_TOPDIR)/include/Make/Script.make
 

Deleted: grass/trunk/scripts/db.dropcolumn/db.dropcol.html
===================================================================
--- grass/trunk/scripts/db.dropcolumn/db.dropcol.html	2009-06-23 14:14:07 UTC (rev 38043)
+++ grass/trunk/scripts/db.dropcolumn/db.dropcol.html	2009-06-23 14:35:39 UTC (rev 38044)
@@ -1,42 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>db.dropcol</em> drops a column from an attribute table.
-If the <b>-f</b> force flag is not given then nothing is removed, instead
-a preview of the action to be taken is printed.
-
-<h2>NOTES</h2>
-
-<em>db.dropcol</em> is a front-end to <em>db.execute</em> to allow easier
-usage with a special workaround for the SQLite driver to support column
-drop.
-
-<h2>EXAMPLES</h2>
-
-Dropping a column (Spearfish):
-<p>
-<div class="code"><pre>
-# work on own copy
-g.copy vect=roads,myroads
-db.describe -c myroads
-
-# only shows what would happen:
-db.dropcol myroads column=label
-
-# actually drops the column
-db.dropcol -f myroads column=label
-
-db.describe -c myroads
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em><a HREF="db.droptable.html">db.droptable</a></em>,
-<em><a HREF="db.execute.html">db.execute</a></em>,
-<em><a HREF="v.db.dropcol.html">v.db.dropcol</a></em>
-
-
-<h2>AUTHOR</h2>
-
-Markus Neteler
-
-<p><i>Last changed: $Date$</i>

Deleted: grass/trunk/scripts/db.dropcolumn/db.dropcol.py
===================================================================
--- grass/trunk/scripts/db.dropcolumn/db.dropcol.py	2009-06-23 14:14:07 UTC (rev 38043)
+++ grass/trunk/scripts/db.dropcolumn/db.dropcol.py	2009-06-23 14:35:39 UTC (rev 38044)
@@ -1,116 +0,0 @@
-#!/usr/bin/env python
-
-############################################################################
-#
-# MODULE:       db.dropcolumn
-# AUTHOR(S):   	Markus Neteler
-#               Converted to Python by Glynn Clements
-# PURPOSE:      interface to db.execute to drop a column from an 
-#               attribute table
-#               - with special trick for SQLite
-# COPYRIGHT:    (C) 2007 by Markus Neteler and 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.
-#
-#############################################################################
-
-
-#%Module
-#%  description: Drops a column from selected attribute table
-#%  keywords: database, attribute table
-#%End
-
-#%flag
-#%  key: f
-#%  description: Force removal (required for actual deletion of files)
-#%end
-
-#%option
-#% key: table
-#% type: string
-#% key_desc : name
-#% description: Table from which to drop attribute column
-#% required : yes
-#% gisprompt: old,dbtable,dbtable
-#%end
-
-#%option
-#% key: column
-#% type: string
-#% description: Name of the column
-#% required : yes
-#% gisprompt: old,dbcolumn,dbcolumn
-#%end
-
-import sys
-import os
-import string
-import grass.script as grass
-
-def main():
-    table = options['table']
-    column = options['column']
-    force = flags['f']
-
-    # check if DB parameters are set, and if not set them.
-    grass.run_command('db.connect', flags = 'c')
-
-    kv = grass.db_connection()
-    database = kv['database']
-    driver = kv['driver']
-    # schema needed for PG?
-
-    if force:
-	grass.message("Forcing ...")
-
-    if column == "cat":
-	grass.warning("Deleting <%s> column which may be needed to keep table connected to a vector map" % column)
-
-    cols = [f[0] for f in grass.db_describe()['cols']]
-    if column not in cols:
-	grass.fatal("Column <%s> not found in table" % column)
-
-    if not force:
-	grass.message("Column <%s> would be deleted." % column)
-	grass.message("")
-	grass.message("You must use the force flag to actually remove it. Exiting.")
-	sys.exit(0)
-
-    if driver == "sqlite":
-	#echo "Using special trick for SQLite"
-	# http://www.sqlite.org/faq.html#q13
-	colnames = []
-	coltypes = []
-	for f in grass.db_describe()['cols']:
-	    if f[0] == column:
-		continue
-	    colnames.append(f[0])
-	    coltypes.append("%s %s" % (f[0], f[1]))
-
-	colnames = ", ".join(colnames)
-	coltypes = ", ".join(coltypes)
-
-	cmds = [
-	    "BEGIN TRANSACTION",
-	    "CREATE TEMPORARY TABLE ${table}_backup(${coldef})",
-	    "INSERT INTO ${table}_backup SELECT ${colnames} FROM ${table}",
-	    "DROP TABLE ${table}",
-	    "CREATE TABLE ${table}(${coldef})",
-	    "INSERT INTO ${table} SELECT ${colnames} FROM ${table}_backup",
-	    "DROP TABLE ${table}_backup",
-	    "COMMIT"
-	    ]
-	tmpl = string.Template(';\n'.join(cmds))
-	sql = tmpl.substitute(table = table, coldef = coltypes, colnames = colnames)
-    else:
-	sql = "ALTER TABLE %s DROP COLUMN %s" % (table, column)
-
-    if grass.write_command('db.execute', database = database, driver = driver,
-			   stdin = sql) != 0:
-	grass.fatal("Cannot continue (problem deleting column).")
-
-if __name__ == "__main__":
-    options, flags = grass.parser()
-    main()

Copied: grass/trunk/scripts/db.dropcolumn/db.dropcolumn.html (from rev 38043, grass/trunk/scripts/db.dropcolumn/db.dropcol.html)
===================================================================
--- grass/trunk/scripts/db.dropcolumn/db.dropcolumn.html	                        (rev 0)
+++ grass/trunk/scripts/db.dropcolumn/db.dropcolumn.html	2009-06-23 14:35:39 UTC (rev 38044)
@@ -0,0 +1,42 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.dropcolumn</em> drops a column from an attribute table.
+If the <b>-f</b> force flag is not given then nothing is removed, instead
+a preview of the action to be taken is printed.
+
+<h2>NOTES</h2>
+
+<em>db.dropcolumn</em> is a front-end to <em>db.execute</em> to allow easier
+usage with a special workaround for the SQLite driver to support column
+drop.
+
+<h2>EXAMPLES</h2>
+
+Dropping a column (Spearfish):
+<p>
+<div class="code"><pre>
+# work on own copy
+g.copy vect=roads,myroads
+db.describe -c myroads
+
+# only shows what would happen:
+db.dropcolumn myroads column=label
+
+# actually drops the column
+db.dropcolumn -f myroads column=label
+
+db.describe -c myroads
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em><a HREF="db.droptable.html">db.droptable</a></em>,
+<em><a HREF="db.execute.html">db.execute</a></em>,
+<em><a HREF="v.db.dropcol.html">v.db.dropcol</a></em>
+
+
+<h2>AUTHOR</h2>
+
+Markus Neteler
+
+<p><i>Last changed: $Date$</i>

Copied: grass/trunk/scripts/db.dropcolumn/db.dropcolumn.py (from rev 38043, grass/trunk/scripts/db.dropcolumn/db.dropcol.py)
===================================================================
--- grass/trunk/scripts/db.dropcolumn/db.dropcolumn.py	                        (rev 0)
+++ grass/trunk/scripts/db.dropcolumn/db.dropcolumn.py	2009-06-23 14:35:39 UTC (rev 38044)
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE:       db.dropcolumn
+# AUTHOR(S):   	Markus Neteler
+#               Converted to Python by Glynn Clements
+# PURPOSE:      interface to db.execute to drop a column from an 
+#               attribute table
+#               - with special trick for SQLite
+# COPYRIGHT:    (C) 2007 by Markus Neteler and 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.
+#
+#############################################################################
+
+
+#%Module
+#%  description: Drops a column from selected attribute table
+#%  keywords: database, attribute table
+#%End
+
+#%flag
+#%  key: f
+#%  description: Force removal (required for actual deletion of files)
+#%end
+
+#%option
+#% key: table
+#% type: string
+#% key_desc : name
+#% description: Table from which to drop attribute column
+#% required : yes
+#% gisprompt: old,dbtable,dbtable
+#%end
+
+#%option
+#% key: column
+#% type: string
+#% description: Name of the column
+#% required : yes
+#% gisprompt: old,dbcolumn,dbcolumn
+#%end
+
+import sys
+import os
+import string
+import grass.script as grass
+
+def main():
+    table = options['table']
+    column = options['column']
+    force = flags['f']
+
+    # check if DB parameters are set, and if not set them.
+    grass.run_command('db.connect', flags = 'c')
+
+    kv = grass.db_connection()
+    database = kv['database']
+    driver = kv['driver']
+    # schema needed for PG?
+
+    if force:
+	grass.message("Forcing ...")
+
+    if column == "cat":
+	grass.warning("Deleting <%s> column which may be needed to keep table connected to a vector map" % column)
+
+    cols = [f[0] for f in grass.db_describe()['cols']]
+    if column not in cols:
+	grass.fatal("Column <%s> not found in table" % column)
+
+    if not force:
+	grass.message("Column <%s> would be deleted." % column)
+	grass.message("")
+	grass.message("You must use the force flag to actually remove it. Exiting.")
+	sys.exit(0)
+
+    if driver == "sqlite":
+	#echo "Using special trick for SQLite"
+	# http://www.sqlite.org/faq.html#q13
+	colnames = []
+	coltypes = []
+	for f in grass.db_describe()['cols']:
+	    if f[0] == column:
+		continue
+	    colnames.append(f[0])
+	    coltypes.append("%s %s" % (f[0], f[1]))
+
+	colnames = ", ".join(colnames)
+	coltypes = ", ".join(coltypes)
+
+	cmds = [
+	    "BEGIN TRANSACTION",
+	    "CREATE TEMPORARY TABLE ${table}_backup(${coldef})",
+	    "INSERT INTO ${table}_backup SELECT ${colnames} FROM ${table}",
+	    "DROP TABLE ${table}",
+	    "CREATE TABLE ${table}(${coldef})",
+	    "INSERT INTO ${table} SELECT ${colnames} FROM ${table}_backup",
+	    "DROP TABLE ${table}_backup",
+	    "COMMIT"
+	    ]
+	tmpl = string.Template(';\n'.join(cmds))
+	sql = tmpl.substitute(table = table, coldef = coltypes, colnames = colnames)
+    else:
+	sql = "ALTER TABLE %s DROP COLUMN %s" % (table, column)
+
+    if grass.write_command('db.execute', database = database, driver = driver,
+			   stdin = sql) != 0:
+	grass.fatal("Cannot continue (problem deleting column).")
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()

Modified: grass/trunk/scripts/db.in.ogr/db.in.ogr.py
===================================================================
--- grass/trunk/scripts/db.in.ogr/db.in.ogr.py	2009-06-23 14:14:07 UTC (rev 38043)
+++ grass/trunk/scripts/db.in.ogr/db.in.ogr.py	2009-06-23 14:35:39 UTC (rev 38044)
@@ -110,7 +110,7 @@
 	grass.try_remove(vectfile)
 
     # get rid of superfluous auto-added cat column (and cat_ if present)
-    grass.run_command('db.dropcol', quiet = True, flags = 'f', table = output,
+    grass.run_command('db.dropcolumn', quiet = True, flags = 'f', table = output,
 		      colum = 'cat', stdout = nuldev, stderr = nuldev)
 
     records = grass.db_describe(output)['nrows']



More information about the grass-commit mailing list