[GRASS-SVN] r62452 - in grass/trunk: lib/python/script scripts/v.unpack
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Oct 28 15:09:33 PDT 2014
Author: martinl
Date: 2014-10-28 15:09:33 -0700 (Tue, 28 Oct 2014)
New Revision: 62452
Modified:
grass/trunk/lib/python/script/db.py
grass/trunk/scripts/v.unpack/v.unpack.py
Log:
v.unpack: fix when default DB connection is not set
Modified: grass/trunk/lib/python/script/db.py
===================================================================
--- grass/trunk/lib/python/script/db.py 2014-10-28 21:16:20 UTC (rev 62451)
+++ grass/trunk/lib/python/script/db.py 2014-10-28 22:09:33 UTC (rev 62452)
@@ -89,18 +89,26 @@
return False
-def db_connection():
+def db_connection(force=False):
"""Return the current database connection parameters
(interface to `db.connect -g`). Example:
>>> db_connection()
{'group': '', 'schema': '', 'driver': 'sqlite', 'database': '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'}
+ :param force True to set up default DB connection if not defined
+
:return: parsed output of db.connect
"""
- return parse_command('db.connect', flags='g')
+ nuldev = file(os.devnull, 'w')
+ conn = parse_command('db.connect', flags='g', stderr=nuldev)
+ nuldev.close()
+ if not conn and force:
+ run_command('db.connect', flags='c')
+ conn = parse_command('db.connect', flags='g')
+
+ return conn
-
def db_select(sql=None, filename=None, table=None, **args):
"""Perform SQL select statement
Modified: grass/trunk/scripts/v.unpack/v.unpack.py
===================================================================
--- grass/trunk/scripts/v.unpack/v.unpack.py 2014-10-28 21:16:20 UTC (rev 62451)
+++ grass/trunk/scripts/v.unpack/v.unpack.py 2014-10-28 22:09:33 UTC (rev 62452)
@@ -139,7 +139,7 @@
# exist fromdb
if os.path.exists(fromdb):
# the db connection in the output mapset
- dbconn = grassdb.db_connection()
+ dbconn = grassdb.db_connection(force=True)
todb = dbconn['database']
# return all tables
list_fromtable = grass.read_command('db.tables', driver='sqlite',
More information about the grass-commit
mailing list