[GRASS-SVN] r54780 - grass/trunk/scripts/v.db.reconnect.all

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jan 27 01:13:19 PST 2013


Author: mmetz
Date: 2013-01-27 01:13:19 -0800 (Sun, 27 Jan 2013)
New Revision: 54780

Modified:
   grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py
Log:
v.db.reconnect.all: add safety checks

Modified: grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py
===================================================================
--- grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py	2013-01-26 22:35:36 UTC (rev 54779)
+++ grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py	2013-01-27 09:13:19 UTC (rev 54780)
@@ -158,11 +158,20 @@
     old_database_subst = None
     if old_database is not None:
 	old_database_subst = substitute_db(old_database)
+
+    new_database_subst = substitute_db(new_database)
     
+    if old_database_subst == new_database_subst and old_schema == new_schema:
+	grass.fatal(_("Old and new database connection is identical. Nothing to do."))
+    
     mapset = grass.gisenv()['MAPSET']
         
     vectors = grass.list_grouped('vect')[mapset]
     num_vectors = len(vectors)
+
+    if flags['c']:
+	# create new database if not existing
+	create_db(new_driver, new_database)
     
     i = 0
     for vect in vectors:
@@ -192,10 +201,13 @@
             grass.debug("DATABASE = '%s' SCHEMA = '%s' TABLE = '%s' ->\n"
                         "      NEW_DATABASE = '%s' NEW_SCHEMA_TABLE = '%s'" % \
                             (old_database, schema, table, new_database, new_schema_table))
+
             do_reconnect = True
 	    if old_database_subst is not None:
 		if database != old_database_subst:
 		    do_reconnect = False
+	    if database == new_database_subst:
+		do_reconnect = False
 	    if schema != old_schema:
 		do_reconnect = False
 		
@@ -203,9 +215,6 @@
                 grass.verbose(_("Reconnecting layer %d...") % layer)
                                           
                 if flags['c']:
-                    # check if database exists
-                    create_db(new_driver, new_database)
-                    
                     # check if table exists in new database
                     copy_tab(driver, database, schema_table,
                              new_driver, new_database, new_schema_table)
@@ -223,8 +232,9 @@
 				  (table, vect))
 
             else:
-                grass.warning(_("Layer <%d> will not be reconnected because "
-                                "database or schema do not match.") % layer)
+		if database != substitute_db(new_database):
+		    grass.warning(_("Layer <%d> will not be reconnected because "
+				    "database or schema do not match.") % layer)
 	
     return 0
 



More information about the grass-commit mailing list