[GRASS-SVN] r66366 - in grass/branches/releasebranch_7_0/lib: python/temporal temporal/lib

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Sep 28 03:07:57 PDT 2015


Author: neteler
Date: 2015-09-28 03:07:57 -0700 (Mon, 28 Sep 2015)
New Revision: 66366

Modified:
   grass/branches/releasebranch_7_0/lib/python/temporal/core.py
   grass/branches/releasebranch_7_0/lib/temporal/lib/default_name.c
Log:
temporal library: Store the default database connection as shell variable substitude to avoid wrong temporal database path's in cases the location was renamed or the path to the grass database changed. (trunk, r65519)

Modified: grass/branches/releasebranch_7_0/lib/python/temporal/core.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/temporal/core.py	2015-09-28 10:06:52 UTC (rev 66365)
+++ grass/branches/releasebranch_7_0/lib/python/temporal/core.py	2015-09-28 10:07:57 UTC (rev 66366)
@@ -847,7 +847,8 @@
             driver,  dbstring = self.tgis_mapsets[mapset]
 
             if dbstring not in self.unique_connections.keys():
-                self.unique_connections[dbstring] = DBConnection(driver)
+                self.unique_connections[dbstring] = DBConnection(backend=driver, 
+                                                                 dbstring=dbstring)
 
             self.connections[mapset] = self.unique_connections[dbstring]
 
@@ -891,7 +892,7 @@
            close all temporal databases that have been opened.
         """
         for key in self.unique_connections.keys():
-            self.unique_connections[key] .close()
+            self.unique_connections[key].close()
 
         self.connected = False
 
@@ -1001,16 +1002,20 @@
 
 class DBConnection(object):
     """This class represents the database interface connection
-       and provides access to the chisen backend modules.
+       and provides access to the chosen backend modules.
 
        The following DBMS are supported:
 
          - sqlite via the sqlite3 standard library
          - postgresql via psycopg2
-
     """
 
-    def __init__(self, backend=None):
+    def __init__(self, backend=None, dbstring=None):
+        """ Constructor of a database connection
+        
+            param backend:The database backend sqlite or pg
+            param dbstring: The database connection string
+        """
         self.connected = False
         if backend is None:
             global tgis_backend
@@ -1024,6 +1029,10 @@
             else:
                 self.dbmi = psycopg2
 
+        if dbstring is None:
+            global tgis_database_string
+            self.dbstring = tgis_database_string
+
         self.msgr = get_tgis_message_interface()
         self.msgr.debug(1, "SQLDatabaseInterfaceConnection constructor")
 
@@ -1048,13 +1057,13 @@
     def connect(self,  dbstring=None):
         """Connect to the DBMI to execute SQL statements
 
-           Supported backends are sqlite3 and postgresql
+            Supported backends are sqlite3 and postgresql
+            
+            param dbstring: The database connection string
         """
         # Connection in the current mapset
         if dbstring is None:
-            global tgis_database_string
-            dbstring = tgis_database_string
-
+            dbstring = self.dbstring
         try:
             if self.dbmi.__name__ == "sqlite3":
                 self.connection = self.dbmi.connect(dbstring,

Modified: grass/branches/releasebranch_7_0/lib/temporal/lib/default_name.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/temporal/lib/default_name.c	2015-09-28 10:06:52 UTC (rev 66365)
+++ grass/branches/releasebranch_7_0/lib/temporal/lib/default_name.c	2015-09-28 10:07:57 UTC (rev 66366)
@@ -40,8 +40,8 @@
 {
     char default_connection[2048];
 
-    G_snprintf(default_connection, 2048, "%s/%s/%s/%s", G_gisdbase(), G_location(),
-               G_mapset(), TGISDB_DEFAULT_SQLITE_PATH);
+    G_snprintf(default_connection, 2048, "$GISDBASE/$LOCATION_NAME/$MAPSET/%s", 
+               TGISDB_DEFAULT_SQLITE_PATH);
 
     return G_store(default_connection);
 }



More information about the grass-commit mailing list