[GRASS-SVN] r62579 - in grass/branches/releasebranch_7_0: lib/python/script scripts/v.unpack
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 3 10:33:12 PST 2014
Author: martinl
Date: 2014-11-03 10:33:12 -0800 (Mon, 03 Nov 2014)
New Revision: 62579
Modified:
grass/branches/releasebranch_7_0/lib/python/script/db.py
grass/branches/releasebranch_7_0/scripts/v.unpack/v.unpack.py
Log:
v.unpack: fix when default DB connection is not set
(merge r62452 from trunk)
Modified: grass/branches/releasebranch_7_0/lib/python/script/db.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/db.py 2014-11-03 18:03:28 UTC (rev 62578)
+++ grass/branches/releasebranch_7_0/lib/python/script/db.py 2014-11-03 18:33:12 UTC (rev 62579)
@@ -89,7 +89,7 @@
return True
return False
-def db_connection():
+def db_connection(force=False):
"""!Return the current database connection parameters
(interface to `db.connect -g'). Example:
@@ -98,13 +98,22 @@
{'group': 'x', 'schema': '', 'driver': 'dbf', 'database': '$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'}
\endcode
- @return parsed output of db.connect
+ :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['driver'] 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
-
+
Note: one of <em>sql</em>, <em>filename</em>, or <em>table</em>
arguments must be provided.
Modified: grass/branches/releasebranch_7_0/scripts/v.unpack/v.unpack.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.unpack/v.unpack.py 2014-11-03 18:03:28 UTC (rev 62578)
+++ grass/branches/releasebranch_7_0/scripts/v.unpack/v.unpack.py 2014-11-03 18:33:12 UTC (rev 62579)
@@ -138,7 +138,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