[GRASS-SVN] r52052 - in grass/trunk: db/db.connect lib/python lib/temporal/t.connect
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 12 14:45:12 PDT 2012
Author: huhabla
Date: 2012-06-12 14:45:12 -0700 (Tue, 12 Jun 2012)
New Revision: 52052
Modified:
grass/trunk/db/db.connect/main.c
grass/trunk/lib/python/db.py
grass/trunk/lib/temporal/t.connect/main.c
Log:
Added -g option to db.connect and updated db.py interface
Modified: grass/trunk/db/db.connect/main.c
===================================================================
--- grass/trunk/db/db.connect/main.c 2012-06-12 16:44:49 UTC (rev 52051)
+++ grass/trunk/db/db.connect/main.c 2012-06-12 21:45:12 UTC (rev 52052)
@@ -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 @@
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 @@
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) {
Modified: grass/trunk/lib/python/db.py
===================================================================
--- grass/trunk/lib/python/db.py 2012-06-12 16:44:49 UTC (rev 52051)
+++ grass/trunk/lib/python/db.py 2012-06-12 21:45:12 UTC (rev 52052)
@@ -64,7 +64,7 @@
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_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 @@
@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
Modified: grass/trunk/lib/temporal/t.connect/main.c
===================================================================
--- grass/trunk/lib/temporal/t.connect/main.c 2012-06-12 16:44:49 UTC (rev 52051)
+++ grass/trunk/lib/temporal/t.connect/main.c 2012-06-12 21:45:12 UTC (rev 52052)
@@ -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 @@
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';
More information about the grass-commit
mailing list