Forráskód Böngészése

pygrass vector: Fixed missing overwrite flag, added vector name check when evwqaluating the database path

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@69545 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 8 éve
szülő
commit
5e4d573bc9

+ 1 - 1
lib/python/pygrass/vector/abstract.py

@@ -363,7 +363,7 @@ class Info(object):
             self.dblinks.add(link)
             self.dblinks.add(link)
             # create the table
             # create the table
             table = link.table()
             table = link.table()
-            table.create(tab_cols)
+            table.create(tab_cols, overwrite=overwrite)
             table.conn.commit()
             table.conn.commit()
 
 
         # check the C function result.
         # check the C function result.

+ 15 - 2
lib/python/pygrass/vector/table.py

@@ -41,10 +41,13 @@ test_vector_name = "table_doctest_map"
 DRIVERS = ('sqlite', 'pg')
 DRIVERS = ('sqlite', 'pg')
 
 
 
 
-def get_path(path):
+def get_path(path, vect_name=None):
     """Return the full path to the database; replacing environment variable
     """Return the full path to the database; replacing environment variable
     with real values
     with real values
 
 
+    :param path: The path with substitutional parameter
+    :param vect_name: The name of the vector map
+
     >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
     >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
     >>> new_path = get_path(path)
     >>> new_path = get_path(path)
     >>> from grass.script.core import gisenv
     >>> from grass.script.core import gisenv
@@ -54,6 +57,15 @@ def get_path(path):
     >>> new_path.replace("//","/") == new_path2.replace("//","/")
     >>> new_path.replace("//","/") == new_path2.replace("//","/")
     True
     True
 
 
+    >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/vector/$MAP/sqlite.db'
+    >>> new_path = get_path(path, "test")
+    >>> from grass.script.core import gisenv
+    >>> import os
+    >>> new_path2 = os.path.join(gisenv()['GISDBASE'], gisenv()['LOCATION_NAME'],
+    ...                          gisenv()['MAPSET'], 'vector', 'test', 'sqlite.db')
+    >>> new_path.replace("//","/") == new_path2.replace("//","/")
+    True
+
     """
     """
     if "$" not in path:
     if "$" not in path:
         return path
         return path
@@ -62,6 +74,7 @@ def get_path(path):
         path = path.replace('$GISDBASE', mapset.gisdbase)
         path = path.replace('$GISDBASE', mapset.gisdbase)
         path = path.replace('$LOCATION_NAME', mapset.location)
         path = path.replace('$LOCATION_NAME', mapset.location)
         path = path.replace('$MAPSET', mapset.name)
         path = path.replace('$MAPSET', mapset.name)
+        path = path.replace('$MAP', vect_name)
         return path
         return path
 
 
 
 
@@ -745,7 +758,7 @@ class Link(object):
             for t in (np.int8, np.int16, np.int32, np.int64, np.uint8,
             for t in (np.int8, np.int16, np.int32, np.int64, np.uint8,
                       np.uint16, np.uint32, np.uint64):
                       np.uint16, np.uint32, np.uint64):
                 sqlite3.register_adapter(t, long)
                 sqlite3.register_adapter(t, long)
-            dbpath = get_path(self.database)
+            dbpath = get_path(self.database, self.table_name)
             dbdirpath = os.path.split(dbpath)[0]
             dbdirpath = os.path.split(dbpath)[0]
             if not os.path.exists(dbdirpath):
             if not os.path.exists(dbdirpath):
                 os.mkdir(dbdirpath)
                 os.mkdir(dbdirpath)