[GRASS-SVN] r69545 - grass/trunk/lib/python/pygrass/vector
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Sep 21 15:09:34 PDT 2016
Author: huhabla
Date: 2016-09-21 15:09:34 -0700 (Wed, 21 Sep 2016)
New Revision: 69545
Modified:
grass/trunk/lib/python/pygrass/vector/abstract.py
grass/trunk/lib/python/pygrass/vector/table.py
Log:
pygrass vector: Fixed missing overwrite flag, added vector name check when evwqaluating the database path
Modified: grass/trunk/lib/python/pygrass/vector/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/abstract.py 2016-09-21 21:55:37 UTC (rev 69544)
+++ grass/trunk/lib/python/pygrass/vector/abstract.py 2016-09-21 22:09:34 UTC (rev 69545)
@@ -363,7 +363,7 @@
self.dblinks.add(link)
# create the table
table = link.table()
- table.create(tab_cols)
+ table.create(tab_cols, overwrite=overwrite)
table.conn.commit()
# check the C function result.
Modified: grass/trunk/lib/python/pygrass/vector/table.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/table.py 2016-09-21 21:55:37 UTC (rev 69544)
+++ grass/trunk/lib/python/pygrass/vector/table.py 2016-09-21 22:09:34 UTC (rev 69545)
@@ -41,10 +41,13 @@
DRIVERS = ('sqlite', 'pg')
-def get_path(path):
+def get_path(path, vect_name=None):
"""Return the full path to the database; replacing environment variable
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'
>>> new_path = get_path(path)
>>> from grass.script.core import gisenv
@@ -54,6 +57,15 @@
>>> new_path.replace("//","/") == new_path2.replace("//","/")
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:
return path
@@ -62,6 +74,7 @@
path = path.replace('$GISDBASE', mapset.gisdbase)
path = path.replace('$LOCATION_NAME', mapset.location)
path = path.replace('$MAPSET', mapset.name)
+ path = path.replace('$MAP', vect_name)
return path
@@ -745,7 +758,7 @@
for t in (np.int8, np.int16, np.int32, np.int64, np.uint8,
np.uint16, np.uint32, np.uint64):
sqlite3.register_adapter(t, long)
- dbpath = get_path(self.database)
+ dbpath = get_path(self.database, self.table_name)
dbdirpath = os.path.split(dbpath)[0]
if not os.path.exists(dbdirpath):
os.mkdir(dbdirpath)
More information about the grass-commit
mailing list