[GRASS-SVN] r54579 - grass/trunk/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 8 07:35:41 PST 2013


Author: martinl
Date: 2013-01-08 07:35:40 -0800 (Tue, 08 Jan 2013)
New Revision: 54579

Modified:
   grass/trunk/lib/python/script/db.py
Log:
pythonlib: db_table_exist() - be silent


Modified: grass/trunk/lib/python/script/db.py
===================================================================
--- grass/trunk/lib/python/script/db.py	2013-01-08 15:04:25 UTC (rev 54578)
+++ grass/trunk/lib/python/script/db.py	2013-01-08 15:35:40 UTC (rev 54579)
@@ -67,18 +67,25 @@
 # run "db.connect -g" and parse output
 
 def db_table_exist(table, **args):
-    """!Return True if database table exists, False otherwise
+    """!Check if table exists.
 
+    If no driver or database are given, then default settings is used
+    (check db_connection()).
+
     @param table table name
-    @param args
+    @param driver DB driver 
+    @param database DB to check
 
     @return True for success, False otherwise
     """
-    result = run_command('db.describe', flags = 'c', table = table, **args)
-    if result == 0:
-            return True
-    else:
-            return False
+    nuldev = file(os.devnull, 'w+')
+    ret = run_command('db.describe', flags = 'c', table = table,
+                      stdout = nuldev, stderr = nuldev, **args)
+    nuldev.close()
+    
+    if ret == 0:
+        return True
+    return False
 
 def db_connection():
     """!Return the current database connection parameters



More information about the grass-commit mailing list