浏览代码

pythonlib: db_table_exist() - be silent

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54579 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 年之前
父节点
当前提交
bab6d7cc6d
共有 1 个文件被更改,包括 14 次插入7 次删除
  1. 14 7
      lib/python/script/db.py

+ 14 - 7
lib/python/script/db.py

@@ -67,18 +67,25 @@ def db_describe(table, **args):
 # 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