瀏覽代碼

Added -g option to db.connect and updated db.py interface

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@52052 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 13 年之前
父節點
當前提交
14628d5e58
共有 3 個文件被更改,包括 32 次插入14 次删除
  1. 24 1
      db/db.connect/main.c
  2. 3 4
      lib/python/db.py
  3. 5 9
      lib/temporal/t.connect/main.c

+ 24 - 1
db/db.connect/main.c

@@ -30,7 +30,7 @@
 int main(int argc, char *argv[])
 {
     dbConnection conn;
-    struct Flag *print, *check_set_default, *def;
+    struct Flag *print, *shell, *check_set_default, *def;
 
     /*    struct Option *driver, *database, *user, *password, *keycol; */
     struct Option *driver, *database, *schema, *group;
@@ -52,6 +52,11 @@ int main(int argc, char *argv[])
     print->description = _("Print current connection parameters and exit");
     print->guisection = _("Print");
 
+    shell = G_define_flag();
+    shell->key = 'g';
+    shell->description = _("Print current connection parameters using shell style and exit");
+    shell->guisection = _("Print");
+
     check_set_default = G_define_flag();
     check_set_default->key = 'c';
     check_set_default->description =
@@ -106,6 +111,24 @@ int main(int argc, char *argv[])
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
+    if (shell->answer) {
+	/* get and print connection in shell style */
+	if (db_get_connection(&conn) == DB_OK) {
+	    fprintf(stdout, "driver=%s\n",
+		    conn.driverName ? conn.driverName : "");
+	    fprintf(stdout, "database=%s\n",
+		    conn.databaseName ? conn.databaseName : "");
+	    fprintf(stdout, "schema=%s\n",
+		    conn.schemaName ? conn.schemaName : "");
+	    fprintf(stdout, "group=%s\n", conn.group ? conn.group : "");
+	}
+	else
+	    G_fatal_error(_("Database connection not defined. "
+			    "Run db.connect."));
+
+	exit(EXIT_SUCCESS);
+    }
+
     if (print->answer) {
 	/* get and print connection */
 	if (db_get_connection(&conn) == DB_OK) {

+ 3 - 4
lib/python/db.py

@@ -64,7 +64,7 @@ def db_describe(table, **args):
     
     return result
 
-# run "db.connect -p" and parse output
+# run "db.connect -g" and parse output
 
 def db_table_exist(table, **args):
     """!Return True if database table exists, False otherwise
@@ -82,7 +82,7 @@ def db_table_exist(table, **args):
 
 def db_connection():
     """!Return the current database connection parameters
-    (interface to `db.connect -p'). Example:
+    (interface to `db.connect -g'). Example:
 
     \code
     >>> grass.db_connection()
@@ -91,8 +91,7 @@ def db_connection():
 
     @return parsed output of db.connect
     """
-    s = read_command('db.connect', flags = 'p')
-    return parse_key_val(s, sep = ':')
+    return parse_command('db.connect', flags = 'g')
 
 def db_select(sql = None, filename = None, table = None, **args):
     """!Perform SQL select statement

+ 5 - 9
lib/temporal/t.connect/main.c

@@ -1,14 +1,10 @@
 
 /****************************************************************************
  *
- * MODULE:       db.connect
- * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
- *               Alex Shevlakov <sixote yahoo.com>, 
- *               Glynn Clements <glynn gclements.plus.com>,
- *               Markus Neteler <neteler itc.it>,
- *               Hamish Bowman <hamish_b yahoo com>
- *               Martin Landa <landa.martin gmail.com> ('d' flag)
- * PURPOSE:      set parameters for connection to database
+ * MODULE:       t.connect
+ * AUTHOR(S):    Soeren Gebbert, based on db.connect
+ *
+ * PURPOSE:      Prints/sets general temporal GIS database connection for current mapset.
  * COPYRIGHT:    (C) 2002-2010 by the GRASS Development Team
  *
  *               This program is free software under the GNU General Public
@@ -39,7 +35,7 @@ int main(int argc, char *argv[])
     G_add_keyword(_("attribute table"));
     G_add_keyword(_("connection settings"));
     module->description =
-	_("Prints/sets general TGIS DB connection for current mapset.");
+	_("Prints/sets general temporal GIS database connection for current mapset.");
 
     print = G_define_flag();
     print->key = 'p';