[QGIS Commit] r10795 - in trunk/qgis/src: plugins/grass plugins/grass/config plugins/grass/modules plugins/grass/scripts providers/grass

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu May 14 16:13:15 EDT 2009


Author: rblazek
Date: 2009-05-14 16:13:14 -0400 (Thu, 14 May 2009)
New Revision: 10795

Added:
   trunk/qgis/src/plugins/grass/modules/qgis.db.connect-login.pg.1.png
   trunk/qgis/src/plugins/grass/modules/qgis.db.connect-login.pg.qgm
   trunk/qgis/src/plugins/grass/scripts/
   trunk/qgis/src/plugins/grass/scripts/CMakeLists.txt
   trunk/qgis/src/plugins/grass/scripts/qgis.db.connect-login.pg.py
Modified:
   trunk/qgis/src/plugins/grass/CMakeLists.txt
   trunk/qgis/src/plugins/grass/config/default.qgc
   trunk/qgis/src/providers/grass/qgsgrass.cpp
Log:
fixed ticket #1173, new script which runs both db.connect and db.login (if necessary) for postgres database, connection is tested

Modified: trunk/qgis/src/plugins/grass/CMakeLists.txt
===================================================================
--- trunk/qgis/src/plugins/grass/CMakeLists.txt	2009-05-14 17:03:43 UTC (rev 10794)
+++ trunk/qgis/src/plugins/grass/CMakeLists.txt	2009-05-14 20:13:14 UTC (rev 10795)
@@ -1,5 +1,5 @@
 
-SUBDIRS(config modules themes)
+SUBDIRS(config modules scripts themes)
 
 ADD_DEFINITIONS(-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\")
 ADD_DEFINITIONS(-DHAVE_OPENPTY=${HAVE_OPENPTY})

Modified: trunk/qgis/src/plugins/grass/config/default.qgc
===================================================================
--- trunk/qgis/src/plugins/grass/config/default.qgc	2009-05-14 17:03:43 UTC (rev 10794)
+++ trunk/qgis/src/plugins/grass/config/default.qgc	2009-05-14 20:13:14 UTC (rev 10795)
@@ -403,6 +403,7 @@
 		<section label="Database management">
 			<grass name="db.connect"/>
 			<grass name="db.connect.schema"/>
+			<grass name="qgis.db.connect-login.pg"/>
 			<grass name="v.db.reconnect.all"/>
 			<grass name="db.login"/>
 			<grass name="db.in.ogr"/>

Added: trunk/qgis/src/plugins/grass/modules/qgis.db.connect-login.pg.1.png
===================================================================
(Binary files differ)


Property changes on: trunk/qgis/src/plugins/grass/modules/qgis.db.connect-login.pg.1.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/qgis/src/plugins/grass/modules/qgis.db.connect-login.pg.qgm
===================================================================
--- trunk/qgis/src/plugins/grass/modules/qgis.db.connect-login.pg.qgm	                        (rev 0)
+++ trunk/qgis/src/plugins/grass/modules/qgis.db.connect-login.pg.qgm	2009-05-14 20:13:14 UTC (rev 10795)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">
+
+<qgisgrassmodule label="Set PostgreSQL DB connection" module="qgis.db.connect-login.pg.py">
+	<option key="database" />
+	<option key="schema" />
+	<option key="host" />
+	<option key="port"/>
+	<option key="user"/>
+	<option key="password"/>
+</qgisgrassmodule>

Added: trunk/qgis/src/plugins/grass/scripts/CMakeLists.txt
===================================================================
--- trunk/qgis/src/plugins/grass/scripts/CMakeLists.txt	                        (rev 0)
+++ trunk/qgis/src/plugins/grass/scripts/CMakeLists.txt	2009-05-14 20:13:14 UTC (rev 10795)
@@ -0,0 +1,5 @@
+
+FILE (GLOB MODULE_FILES *.py )
+INSTALL (FILES ${MODULE_FILES}
+         DESTINATION ${QGIS_DATA_DIR}/grass/scripts
+	 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE )

Added: trunk/qgis/src/plugins/grass/scripts/qgis.db.connect-login.pg.py
===================================================================
--- trunk/qgis/src/plugins/grass/scripts/qgis.db.connect-login.pg.py	                        (rev 0)
+++ trunk/qgis/src/plugins/grass/scripts/qgis.db.connect-login.pg.py	2009-05-14 20:13:14 UTC (rev 10795)
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE:       qgis.db.connect-login.py
+# AUTHOR(S):    Radim Blazek
+#
+# PURPOSE:      Connect to Postgresql
+# COPYRIGHT:    (C) 2009 by Radim Blazek
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+#%Module
+#% description: Make connection to PostgreSQL database and login.
+#% keywords: database
+#%End
+
+#%option
+#% key: host
+#% type: string
+#% label: Host
+#% description: Host name of the machine on which the server is running. 
+#% required : no
+#%end
+
+#%option
+#% key: port
+#% type: integer
+#% label: Port
+#% description: TCP port on which the server is listening, usually 5432.
+#% required : no
+#%end
+
+#%option
+#% key: database
+#% type: string
+#% key_desc : name
+#% gisprompt: old_dbname,dbname,dbname
+#% label: Database
+#% description: Database name
+#% required : yes
+#%end
+
+#%option
+#% key: schema
+#% type: string
+#% label: Schema
+#% description: Database schema.
+#% required : no
+#%end
+
+#%option
+#% key: user
+#% type: string
+#% label: User
+#% description: Connect to the database as the user username instead of the  default. 
+#% required : no
+#%end
+
+#%option
+#% key: password
+#% type: string
+#% label: Password
+#% description: Password will be stored in file!
+#% required : no
+#%end
+
+import sys
+import os
+import string
+import grass
+
+def main():
+    host = options['host']
+    port = options['port']
+    database = options['database']
+    schema = options['schema']
+    user = options['user']
+    password = options['password']
+
+    #if not maptable:
+    #	grass.fatal("There is no table connected to this map. Cannot join any column.")
+
+    # Test connection
+    conn = "dbname=" + database
+    if host: conn += ",host=" + host
+    if port: conn += ",port=" + host
+
+    # Unfortunately we cannot test untill user/password is set 
+    if user or password:
+        print "Setting login (db.login) ... "
+        sys.stdout.flush()
+        if grass.run_command('db.login', driver = "pg", database = conn, user = user, password = password) != 0:
+	    grass.fatal("Cannot login")
+
+    # Try to connect
+    print "Testing connection ..."
+    sys.stdout.flush()
+    if grass.run_command('db.select', quiet = True, flags='c', driver= "pg", database=conn, sql="select version()" ) != 0:
+	if user or password:
+	    print "Deleting login (db.login) ..."
+	    sys.stdout.flush()
+	    if grass.run_command('db.login', quiet = True, driver = "pg", database = conn, user = "", password = "") != 0:
+		print "Cannot delete login."
+		sys.stdout.flush()
+        grass.fatal("Cannot connect to database.")
+  
+    if grass.run_command('db.connect', driver = "pg", database = conn, schema = schema) != 0:
+        grass.fatal("Cannot connect to database.")
+	
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()


Property changes on: trunk/qgis/src/plugins/grass/scripts/qgis.db.connect-login.pg.py
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/qgis/src/providers/grass/qgsgrass.cpp
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrass.cpp	2009-05-14 17:03:43 UTC (rev 10794)
+++ trunk/qgis/src/providers/grass/qgsgrass.cpp	2009-05-14 20:13:14 UTC (rev 10795)
@@ -181,6 +181,7 @@
 #endif
   QString path = "PATH=" + gisBase + "/bin";
   path.append( sep + gisBase + "/scripts" );
+  path.append( sep +  QgsApplication::pkgDataPath() + "/grass/scripts/" );
 
   // On windows the GRASS libraries are in
   // QgsApplication::prefixPath(), we have to add them



More information about the QGIS-commit mailing list