소스 검색

v.db.addtable: fails gracefully when vector is open level 1

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70373 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 8 년 전
부모
커밋
be5a8a466b
1개의 변경된 파일12개의 추가작업 그리고 5개의 파일을 삭제
  1. 12 5
      scripts/v.db.addtable/v.db.addtable.py

+ 12 - 5
scripts/v.db.addtable/v.db.addtable.py

@@ -86,7 +86,7 @@ def main():
         grass.verbose(_("Using user specified table name: %s") % table)
         grass.verbose(_("Using user specified table name: %s") % table)
 
 
     # check if DB parameters are set, and if not set them.
     # check if DB parameters are set, and if not set them.
-    grass.run_command('db.connect', flags='c')
+    grass.run_command('db.connect', flags='c', quiet=True)
     grass.verbose(_("Creating new DB connection based on default mapset settings..."))
     grass.verbose(_("Creating new DB connection based on default mapset settings..."))
     kv = grass.db_connection()
     kv = grass.db_connection()
     database = kv['database']
     database = kv['database']
@@ -133,10 +133,17 @@ def main():
                       map=map_name, database=database, driver=driver,
                       map=map_name, database=database, driver=driver,
                       layer=layer, table=table, key=key)
                       layer=layer, table=table, key=key)
 
 
-    # finally we have to add cats into the attribute DB to make modules such as v.what.rast happy:
-    # (creates new row for each vector line):
-    grass.run_command('v.to.db', map=map_name, layer=layer,
-                      option='cat', column=key, qlayer=layer)
+    # finally we have to add cats into the attribute DB to make
+    # modules such as v.what.rast happy: (creates new row for each
+    # vector line):
+    try:
+        grass.run_command('v.to.db', map=map_name, layer=layer,
+                          option='cat', column=key, qlayer=layer)
+    except CalledModuleError:
+        # remove link
+        grass.run_command('v.db.connect', quiet=True, flags='d',
+                          map=map_name, layer=layer)
+        return 1
 
 
     grass.verbose(_("Current attribute table links:"))
     grass.verbose(_("Current attribute table links:"))
     if grass.verbosity() > 2:
     if grass.verbosity() > 2: