Przeglądaj źródła

Show a warning if a temporal database connection is defined, but the database file is not present

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@65442 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 10 lat temu
rodzic
commit
a489952064
1 zmienionych plików z 14 dodań i 3 usunięć
  1. 14 3
      lib/python/temporal/core.py

+ 14 - 3
lib/python/temporal/core.py

@@ -437,6 +437,7 @@ def get_available_temporal_mapsets():
                   database) are the values
     """
     global c_library_interface
+    global message_interface
 
     mapsets = c_library_interface.available_mapsets()
 
@@ -447,7 +448,17 @@ def get_available_temporal_mapsets():
         database = c_library_interface.get_database_name(mapset)
 
         if driver and database:
-            tgis_mapsets[mapset] = (driver,  database)
+            # Check if the temporal sqlite database exists
+            # We need to set non-existing databases in case the mapset is the current mapset
+            # to create it
+            if (driver == "sqlite" and os.path.exists(database)) or mapset == get_current_mapset() :
+                tgis_mapsets[mapset] = (driver,  database)
+
+            # We need to warn if the connection is defined but the database does not
+            # exists
+            if driver == "sqlite" and not os.path.exists(database):
+                message_interface.warning("Temporal database connection defined as:\n" + \
+                                          database + "\nBut database file does not exists.")
 
     return tgis_mapsets
 
@@ -769,7 +780,7 @@ def create_temporal_database(dbif):
                                         "postgresql_indexes.sql"), 'r').read()
 
     # Connect now to the database
-    if not dbif.connected:
+    if dbif.connected is not True:
         dbif.connect()
 
     # Execute the SQL statements for sqlite
@@ -879,7 +890,7 @@ class SQLDatabaseInterfaceConnection(object):
             driver,  dbstring = self.tgis_mapsets[mapset]
             conn = self.connections[mapset]
             if conn.is_connected() is False:
-                conn .connect(dbstring)
+                conn.connect(dbstring)
 
         self.connected = True