瀏覽代碼

python temporal: First steps to allow distributed temporal databases. The C-library interface supports now the request of temporal database driver and name/connection string. Added several TODOs to the SQLDatabaseInterfaceConnection class that must implement mapset specific database connections and cursors.

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61762 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 10 年之前
父節點
當前提交
581291f7fe
共有 2 個文件被更改,包括 345 次插入236 次删除
  1. 212 141
      lib/python/temporal/c_libraries_interface.py
  2. 133 95
      lib/python/temporal/core.py

+ 212 - 141
lib/python/temporal/c_libraries_interface.py

@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
-"""!@package grass.pygrass.massages
+"""@package grass.pygrass.massages
 
 
 @brief Temporal Framework GRASS C-library interface
 @brief Temporal Framework GRASS C-library interface
 
 
@@ -20,11 +20,13 @@ from multiprocessing import Process, Lock, Pipe
 import logging
 import logging
 from ctypes import *
 from ctypes import *
 from core import *
 from core import *
+import core as corefunc
 import grass.lib.gis as libgis
 import grass.lib.gis as libgis
 import grass.lib.raster as libraster
 import grass.lib.raster as libraster
 import grass.lib.vector as libvector
 import grass.lib.vector as libvector
 import grass.lib.date as libdate
 import grass.lib.date as libdate
 import grass.lib.raster3d as libraster3d
 import grass.lib.raster3d as libraster3d
+import grass.lib.temporal as libtgis
 
 
 ###############################################################################
 ###############################################################################
 
 
@@ -39,20 +41,58 @@ class RPCDefs(object):
     MAP_EXISTS=6
     MAP_EXISTS=6
     READ_MAP_INFO=7
     READ_MAP_INFO=7
     AVAILABLE_MAPSETS = 8
     AVAILABLE_MAPSETS = 8
+    GET_DRIVER_NAME = 9
+    GET_DATABASE_NAME = 10
 
 
     TYPE_RASTER=0
     TYPE_RASTER=0
     TYPE_RASTER3D=1
     TYPE_RASTER3D=1
     TYPE_VECTOR=2
     TYPE_VECTOR=2
 
 
 ###############################################################################
 ###############################################################################
-def available_mapsets(lock, conn, data):
-    """!Return all available mapsets the user can access as a list of strings
+
+def _get_driver_name(lock, conn, data):
+    """Return the temporal database driver of a specific mapset
     
     
-       @param lock A multiprocessing.Lock instance
-       @param conn A multiprocessing.Pipe instance used to send True or False
-       @param data The list of data entries [function_id]
+       :param lock: A multiprocessing.Lock instance
+       :param conn: A multiprocessing.Pipe instance used to send True or False
+       :param data: The mapset as list entry 1 [function_id, mapset]
        
        
-       @return Names of available mapsets as list of strings
+       :returns: Name of the driver or None if no temporal database present
+    """
+    drstring = libtgis.tgis_get_mapset_driver_name(data[1])
+    
+    conn.send(drstring) 
+
+###############################################################################
+
+def _get_database_name(lock, conn, data):
+    """Return the temporal database name of a specific mapset
+    
+       :param lock: A multiprocessing.Lock instance
+       :param conn: A multiprocessing.Pipe instance used to send True or False
+       :param data: The mapset as list entry 1 [function_id, mapset]
+       
+       :returns: Name of the database or None if no temporal database present
+    """
+    dbstring = libtgis.tgis_get_mapset_database_name(data[1])
+    if dbstring:
+        # We substitute GRASS variables if they are located in the database string
+        # This behavior is in conjunction with db.connect
+        dbstring = dbstring.replace("$GISDBASE", corefunc.current_gisdbase)
+        dbstring = dbstring.replace("$LOCATION_NAME", corefunc.current_location)
+        dbstring = dbstring.replace("$MAPSET", corefunc.current_mapset)
+    conn.send(dbstring) 
+
+###############################################################################
+
+def _available_mapsets(lock, conn, data):
+    """Return all available mapsets the user can access as a list of strings
+    
+       :param lock: A multiprocessing.Lock instance
+       :param conn: A multiprocessing.Pipe instance used to send True or False
+       :param data: The list of data entries [function_id]
+       
+       :returns: Names of available mapsets as list of strings
     """
     """
     
     
     mapsets = libgis.G_get_available_mapsets()
     mapsets = libgis.G_get_available_mapsets()
@@ -83,12 +123,12 @@ def available_mapsets(lock, conn, data):
     conn.send(mapset_list) 
     conn.send(mapset_list) 
 
 
 def _has_timestamp(lock, conn, data):
 def _has_timestamp(lock, conn, data):
-    """!Check if the file based GRASS timestamp is present and send
+    """Check if the file based GRASS timestamp is present and send
        True or False using the provided pipe.
        True or False using the provided pipe.
 
 
-       @param lock A multiprocessing.Lock instance
-       @param conn A multiprocessing.Pipe instance used to send True or False
-       @param data The list of data entries [function_id, maptype, name, mapset, layer]
+       :param lock: A multiprocessing.Lock instance
+       :param conn: A multiprocessing.Pipe instance used to send True or False
+       :param data: The list of data entries [function_id, maptype, name, mapset, layer]
 
 
     """
     """
     maptype = data[1]
     maptype = data[1]
@@ -110,7 +150,7 @@ def _has_timestamp(lock, conn, data):
 ###############################################################################
 ###############################################################################
 
 
 def _read_timestamp(lock, conn, data):
 def _read_timestamp(lock, conn, data):
-    """!Read the file based GRASS timestamp and send
+    """Read the file based GRASS timestamp and send
        the result using the provided pipe.
        the result using the provided pipe.
 
 
        The tuple to be send via pipe: (return value of G_read_*_timestamp, timestamps).
        The tuple to be send via pipe: (return value of G_read_*_timestamp, timestamps).
@@ -126,9 +166,9 @@ def _read_timestamp(lock, conn, data):
 
 
        The end time may be None in case of a time instance.
        The end time may be None in case of a time instance.
 
 
-       @param lock A multiprocessing.Lock instance
-       @param conn A multiprocessing.Pipe instance used to send the result
-       @param data The list of data entries [function_id, maptype, name, mapset, layer]
+       :param lock: A multiprocessing.Lock instance
+       :param conn: A multiprocessing.Pipe instance used to send the result
+       :param data: The list of data entries [function_id, maptype, name, mapset, layer]
 
 
     """
     """
     maptype = data[1]
     maptype = data[1]
@@ -150,7 +190,7 @@ def _read_timestamp(lock, conn, data):
 ###############################################################################
 ###############################################################################
 
 
 def _write_timestamp(lock, conn, data):
 def _write_timestamp(lock, conn, data):
-    """!Write the file based GRASS timestamp
+    """Write the file based GRASS timestamp
        the return values of the called C-functions using the provided pipe.
        the return values of the called C-functions using the provided pipe.
 
 
        The value to be send via pipe is the return value of G_write_*_timestamp.
        The value to be send via pipe is the return value of G_write_*_timestamp.
@@ -159,9 +199,9 @@ def _write_timestamp(lock, conn, data):
        G_write_vector_timestamp and G_write_raster3d_timestamp for the return
        G_write_vector_timestamp and G_write_raster3d_timestamp for the return
        values description.
        values description.
 
 
-       @param lock A multiprocessing.Lock instance
-       @param conn A multiprocessing.Pipe instance used to send True or False
-       @param data The list of data entries [function_id, maptype, name, mapset, layer, timestring]
+       :param lock: A multiprocessing.Lock instance
+       :param conn: A multiprocessing.Pipe instance used to send True or False
+       :param data: The list of data entries [function_id, maptype, name, mapset, layer, timestring]
     """
     """
     maptype = data[1]
     maptype = data[1]
     name = data[2]
     name = data[2]
@@ -188,7 +228,7 @@ def _write_timestamp(lock, conn, data):
 ###############################################################################
 ###############################################################################
 
 
 def _remove_timestamp(lock, conn, data):
 def _remove_timestamp(lock, conn, data):
-    """!Remove the file based GRASS timestamp
+    """Remove the file based GRASS timestamp
        the return values of the called C-functions using the provided pipe.
        the return values of the called C-functions using the provided pipe.
 
 
        The value to be send via pipe is the return value of G_remove_*_timestamp.
        The value to be send via pipe is the return value of G_remove_*_timestamp.
@@ -197,9 +237,9 @@ def _remove_timestamp(lock, conn, data):
        G_remove_vector_timestamp and G_remove_raster3d_timestamp for the return
        G_remove_vector_timestamp and G_remove_raster3d_timestamp for the return
        values description.
        values description.
 
 
-       @param lock A multiprocessing.Lock instance
-       @param conn A multiprocessing.Pipe instance used to send True or False
-       @param data The list of data entries [function_id, maptype, name, mapset, layer]
+       :param lock: A multiprocessing.Lock instance
+       :param conn: A multiprocessing.Pipe instance used to send True or False
+       :param data: The list of data entries [function_id, maptype, name, mapset, layer]
 
 
     """
     """
     maptype = data[1]
     maptype = data[1]
@@ -219,14 +259,14 @@ def _remove_timestamp(lock, conn, data):
 ###############################################################################
 ###############################################################################
 
 
 def _map_exists(lock, conn, data):
 def _map_exists(lock, conn, data):
-    """!Check if a map exists in the spatial database
+    """Check if a map exists in the spatial database
 
 
        The value to be send via pipe is True in case the map exists and False
        The value to be send via pipe is True in case the map exists and False
        if not.
        if not.
 
 
-       @param lock A multiprocessing.Lock instance
-       @param conn A multiprocessing.Pipe instance used to send True or False
-       @param data The list of data entries [function_id, maptype, name, mapset]
+       :param lock: A multiprocessing.Lock instance
+       :param conn: A multiprocessing.Pipe instance used to send True or False
+       :param data: The list of data entries [function_id, maptype, name, mapset]
 
 
     """
     """
     maptype = data[1]
     maptype = data[1]
@@ -248,12 +288,12 @@ def _map_exists(lock, conn, data):
 ###############################################################################
 ###############################################################################
 
 
 def _read_map_info(lock, conn, data):
 def _read_map_info(lock, conn, data):
-    """!Read map specific metadata from the spatial database using C-library
+    """Read map specific metadata from the spatial database using C-library
        functions
        functions
 
 
-       @param lock A multiprocessing.Lock instance
-       @param conn A multiprocessing.Pipe instance used to send True or False
-       @param data The list of data entries [function_id, maptype, name, mapset]
+       :param lock: A multiprocessing.Lock instance
+       :param conn: A multiprocessing.Pipe instance used to send True or False
+       :param data: The list of data entries [function_id, maptype, name, mapset]
     """
     """
     maptype = data[1]
     maptype = data[1]
     name = data[2]
     name = data[2]
@@ -270,15 +310,15 @@ def _read_map_info(lock, conn, data):
 ###############################################################################
 ###############################################################################
 
 
 def _read_raster_info(name, mapset):
 def _read_raster_info(name, mapset):
-    """!Read the raster map info from the file system and store the content
+    """Read the raster map info from the file system and store the content
        into a dictionary
        into a dictionary
 
 
        This method uses the ctypes interface to the gis and raster libraries
        This method uses the ctypes interface to the gis and raster libraries
        to read the map metadata information
        to read the map metadata information
 
 
-       @param name The name of the map
-       @param mapset The mapset of the map
-       @return The key value pairs of the map specific metadata, or None in case of an error
+       :param name: The name of the map
+       :param mapset: The mapset of the map
+       :returns: The key value pairs of the map specific metadata, or None in case of an error
     """
     """
 
 
     kvp = {}
     kvp = {}
@@ -349,15 +389,15 @@ def _read_raster_info(name, mapset):
 ###############################################################################
 ###############################################################################
 
 
 def _read_raster3d_info(name, mapset):
 def _read_raster3d_info(name, mapset):
-    """!Read the 3D raster map info from the file system and store the content
+    """Read the 3D raster map info from the file system and store the content
        into a dictionary
        into a dictionary
 
 
        This method uses the ctypes interface to the gis and raster3d libraries
        This method uses the ctypes interface to the gis and raster3d libraries
        to read the map metadata information
        to read the map metadata information
 
 
-       @param name The name of the map
-       @param mapset The mapset of the map
-       @return The key value pairs of the map specific metadata, or None in case of an error
+       :param name: The name of the map
+       :param mapset: The mapset of the map
+       :returns: The key value pairs of the map specific metadata, or None in case of an error
     """
     """
 
 
     kvp = {}
     kvp = {}
@@ -430,15 +470,15 @@ def _read_raster3d_info(name, mapset):
 ###############################################################################
 ###############################################################################
 
 
 def _read_vector_info(name, mapset):
 def _read_vector_info(name, mapset):
-    """!Read the vector map info from the file system and store the content
+    """Read the vector map info from the file system and store the content
        into a dictionary
        into a dictionary
 
 
        This method uses the ctypes interface to the vector libraries
        This method uses the ctypes interface to the vector libraries
        to read the map metadata information
        to read the map metadata information
 
 
-       @param name The name of the map
-       @param mapset The mapset of the map
-       @return The key value pairs of the map specific metadata, or None in case of an error
+       :param name: The name of the map
+       :param mapset: The mapset of the map
+       :returns: The key value pairs of the map specific metadata, or None in case of an error
     """
     """
 
 
     kvp = {}
     kvp = {}
@@ -530,7 +570,7 @@ def _read_vector_info(name, mapset):
 ###############################################################################
 ###############################################################################
 
 
 def _convert_timestamp_from_grass(ts):
 def _convert_timestamp_from_grass(ts):
-    """!Convert a GRASS file based timestamp into the temporal framework
+    """Convert a GRASS file based timestamp into the temporal framework
        format datetime or integer.
        format datetime or integer.
 
 
        A tuple of two datetime objects (start, end) is returned in case of absolute time.
        A tuple of two datetime objects (start, end) is returned in case of absolute time.
@@ -540,7 +580,7 @@ def _convert_timestamp_from_grass(ts):
        Note:
        Note:
        The end time will be set to None in case of a time instance.
        The end time will be set to None in case of a time instance.
 
 
-       @param ts grass.lib.gis.TimeStamp object created by G_read_*_timestamp
+       :param ts grass.lib.gis.TimeStamp object created by G_read_*_timestamp
     """
     """
 
 
     dt1 = libgis.DateTime()
     dt1 = libgis.DateTime()
@@ -616,14 +656,14 @@ def _stop(lock, conn, data):
 ###############################################################################
 ###############################################################################
 
 
 def c_library_server(lock, conn):
 def c_library_server(lock, conn):
-    """!The GRASS C-libraries server function designed to be a target for
+    """The GRASS C-libraries server function designed to be a target for
        multiprocessing.Process
        multiprocessing.Process
 
 
-       @param lock A multiprocessing.Lock
-       @param conn A multiprocessing.Pipe
+       :param lock: A multiprocessing.Lock
+       :param conn: A multiprocessing.Pipe
     """
     """
     # Crerate the function array
     # Crerate the function array
-    functions = [0]*9
+    functions = [0]*11
     functions[RPCDefs.STOP] = _stop
     functions[RPCDefs.STOP] = _stop
     functions[RPCDefs.HAS_TIMESTAMP] = _has_timestamp
     functions[RPCDefs.HAS_TIMESTAMP] = _has_timestamp
     functions[RPCDefs.WRITE_TIMESTAMP] = _write_timestamp
     functions[RPCDefs.WRITE_TIMESTAMP] = _write_timestamp
@@ -631,7 +671,9 @@ def c_library_server(lock, conn):
     functions[RPCDefs.REMOVE_TIMESTAMP] = _remove_timestamp
     functions[RPCDefs.REMOVE_TIMESTAMP] = _remove_timestamp
     functions[RPCDefs.READ_MAP_INFO] = _read_map_info
     functions[RPCDefs.READ_MAP_INFO] = _read_map_info
     functions[RPCDefs.MAP_EXISTS] = _map_exists
     functions[RPCDefs.MAP_EXISTS] = _map_exists
-    functions[RPCDefs.AVAILABLE_MAPSETS] = available_mapsets
+    functions[RPCDefs.AVAILABLE_MAPSETS] = _available_mapsets
+    functions[RPCDefs.GET_DRIVER_NAME] = _get_driver_name
+    functions[RPCDefs.GET_DATABASE_NAME] = _get_database_name
 
 
     libgis.G_gisinit("c_library_server")
     libgis.G_gisinit("c_library_server")
     libgis.G_debug(1, "Start C-interface server")
     libgis.G_debug(1, "Start C-interface server")
@@ -645,7 +687,7 @@ def c_library_server(lock, conn):
         lock.release()
         lock.release()
 
 
 class CLibrariesInterface(object):
 class CLibrariesInterface(object):
-    """!Fast and exit-safe interface to GRASS C-libraries functions
+    """Fast and exit-safe interface to GRASS C-libraries functions
 
 
        This class implements a fast and exit-safe interface to the GRASS
        This class implements a fast and exit-safe interface to the GRASS
        gis, raster, 3D raster and vector  C-libraries functions.
        gis, raster, 3D raster and vector  C-libraries functions.
@@ -759,6 +801,11 @@ class CLibrariesInterface(object):
        1
        1
        >>> ciface.has_vector_timestamp("test", tgis.get_current_mapset())
        >>> ciface.has_vector_timestamp("test", tgis.get_current_mapset())
        True
        True
+       
+       >>> ciface.get_driver_name()
+       'sqlite'
+       >>> ciface.get_database_name().split("/")[-1]
+       'sqlite.db'
 
 
        >>> gscript.del_temp_region()
        >>> gscript.del_temp_region()
 
 
@@ -770,9 +817,6 @@ class CLibrariesInterface(object):
         self.server = None
         self.server = None
         self.start_server()
         self.start_server()
 
 
-    def __del__(self):
-        self.stop()
-
     def start_server(self):
     def start_server(self):
         self.client_conn, self.server_conn = Pipe()
         self.client_conn, self.server_conn = Pipe()
         self.lock = Lock()
         self.lock = Lock()
@@ -782,7 +826,7 @@ class CLibrariesInterface(object):
         self.server.start()
         self.server.start()
 
 
     def _check_restart_server(self):
     def _check_restart_server(self):
-        """!Restart the server if it was terminated
+        """Restart the server if it was terminated
         """
         """
         if self.server.is_alive() is True:
         if self.server.is_alive() is True:
             return
             return
@@ -792,11 +836,11 @@ class CLibrariesInterface(object):
         logging.warning("Needed to restart the libgis server")
         logging.warning("Needed to restart the libgis server")
 
 
     def raster_map_exists(self, name, mapset):
     def raster_map_exists(self, name, mapset):
-        """!Check if a raster map exists in the spatial database
+        """Check if a raster map exists in the spatial database
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return True if exists, False if not
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: True if exists, False if not
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.MAP_EXISTS, RPCDefs.TYPE_RASTER,
         self.client_conn.send([RPCDefs.MAP_EXISTS, RPCDefs.TYPE_RASTER,
@@ -804,12 +848,12 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def read_raster_info(self, name, mapset):
     def read_raster_info(self, name, mapset):
-        """!Read the raster map info from the file system and store the content
+        """Read the raster map info from the file system and store the content
            into a dictionary
            into a dictionary
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return The key value pairs of the map specific metadata, or None in case of an error
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: The key value pairs of the map specific metadata, or None in case of an error
         """
         """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.READ_MAP_INFO, RPCDefs.TYPE_RASTER,
         self.client_conn.send([RPCDefs.READ_MAP_INFO, RPCDefs.TYPE_RASTER,
@@ -817,11 +861,11 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def has_raster_timestamp(self, name, mapset):
     def has_raster_timestamp(self, name, mapset):
-        """!Check if a file based raster timetamp exists
+        """Check if a file based raster timetamp exists
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return True if exists, False if not
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: True if exists, False if not
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.HAS_TIMESTAMP, RPCDefs.TYPE_RASTER,
         self.client_conn.send([RPCDefs.HAS_TIMESTAMP, RPCDefs.TYPE_RASTER,
@@ -829,14 +873,14 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def remove_raster_timestamp(self, name, mapset):
     def remove_raster_timestamp(self, name, mapset):
-        """!Remove a file based raster timetamp
+        """Remove a file based raster timetamp
 
 
            Please have a look at the documentation G_remove_raster_timestamp
            Please have a look at the documentation G_remove_raster_timestamp
            for the return values description.
            for the return values description.
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return The return value of G_remove_raster_timestamp
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: The return value of G_remove_raster_timestamp
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.REMOVE_TIMESTAMP, RPCDefs.TYPE_RASTER,
         self.client_conn.send([RPCDefs.REMOVE_TIMESTAMP, RPCDefs.TYPE_RASTER,
@@ -844,7 +888,7 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def read_raster_timestamp(self, name, mapset):
     def read_raster_timestamp(self, name, mapset):
-        """!Read a file based raster timetamp
+        """Read a file based raster timetamp
 
 
            Please have a look at the documentation G_read_raster_timestamp
            Please have a look at the documentation G_read_raster_timestamp
            for the return values description.
            for the return values description.
@@ -856,9 +900,9 @@ class CLibrariesInterface(object):
 
 
            The end time may be None in case of a time instance.
            The end time may be None in case of a time instance.
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return The return value of G_read_raster_timestamp
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: The return value of G_read_raster_timestamp
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.READ_TIMESTAMP, RPCDefs.TYPE_RASTER,
         self.client_conn.send([RPCDefs.READ_TIMESTAMP, RPCDefs.TYPE_RASTER,
@@ -866,7 +910,7 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def write_raster_timestamp(self, name, mapset, timestring):
     def write_raster_timestamp(self, name, mapset, timestring):
-        """!Write a file based raster timetamp
+        """Write a file based raster timetamp
 
 
            Please have a look at the documentation G_write_raster_timestamp
            Please have a look at the documentation G_write_raster_timestamp
            for the return values description.
            for the return values description.
@@ -874,10 +918,10 @@ class CLibrariesInterface(object):
            Note:
            Note:
                Only timestamps of maps from the current mapset can written.
                Only timestamps of maps from the current mapset can written.
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @param timestring A GRASS datetime C-library compatible string
-           @return The return value of G_write_raster_timestamp
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :param timestring: A GRASS datetime C-library compatible string
+           :returns: The return value of G_write_raster_timestamp
         """
         """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.WRITE_TIMESTAMP, RPCDefs.TYPE_RASTER,
         self.client_conn.send([RPCDefs.WRITE_TIMESTAMP, RPCDefs.TYPE_RASTER,
@@ -885,11 +929,11 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def raster3d_map_exists(self, name, mapset):
     def raster3d_map_exists(self, name, mapset):
-        """!Check if a 3D raster map exists in the spatial database
+        """Check if a 3D raster map exists in the spatial database
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return True if exists, False if not
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: True if exists, False if not
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.MAP_EXISTS, RPCDefs.TYPE_RASTER3D,
         self.client_conn.send([RPCDefs.MAP_EXISTS, RPCDefs.TYPE_RASTER3D,
@@ -897,12 +941,12 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def read_raster3d_info(self, name, mapset):
     def read_raster3d_info(self, name, mapset):
-        """!Read the 3D raster map info from the file system and store the content
+        """Read the 3D raster map info from the file system and store the content
            into a dictionary
            into a dictionary
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return The key value pairs of the map specific metadata, or None in case of an error
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: The key value pairs of the map specific metadata, or None in case of an error
         """
         """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.READ_MAP_INFO, RPCDefs.TYPE_RASTER3D,
         self.client_conn.send([RPCDefs.READ_MAP_INFO, RPCDefs.TYPE_RASTER3D,
@@ -910,11 +954,11 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def has_raster3d_timestamp(self, name, mapset):
     def has_raster3d_timestamp(self, name, mapset):
-        """!Check if a file based 3D raster timetamp exists
+        """Check if a file based 3D raster timetamp exists
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return True if exists, False if not
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: True if exists, False if not
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.HAS_TIMESTAMP, RPCDefs.TYPE_RASTER3D,
         self.client_conn.send([RPCDefs.HAS_TIMESTAMP, RPCDefs.TYPE_RASTER3D,
@@ -922,14 +966,14 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def remove_raster3d_timestamp(self, name, mapset):
     def remove_raster3d_timestamp(self, name, mapset):
-        """!Remove a file based 3D raster timetamp
+        """Remove a file based 3D raster timetamp
 
 
            Please have a look at the documentation G_remove_raster3d_timestamp
            Please have a look at the documentation G_remove_raster3d_timestamp
            for the return values description.
            for the return values description.
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return The return value of G_remove_raster3d_timestamp
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: The return value of G_remove_raster3d_timestamp
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.REMOVE_TIMESTAMP, RPCDefs.TYPE_RASTER3D,
         self.client_conn.send([RPCDefs.REMOVE_TIMESTAMP, RPCDefs.TYPE_RASTER3D,
@@ -937,7 +981,7 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def read_raster3d_timestamp(self, name, mapset):
     def read_raster3d_timestamp(self, name, mapset):
-        """!Read a file based 3D raster timetamp
+        """Read a file based 3D raster timetamp
 
 
            Please have a look at the documentation G_read_raster3d_timestamp
            Please have a look at the documentation G_read_raster3d_timestamp
            for the return values description.
            for the return values description.
@@ -949,9 +993,9 @@ class CLibrariesInterface(object):
 
 
            The end time may be None in case of a time instance.
            The end time may be None in case of a time instance.
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return The return value of G_read_raster3d_timestamp
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: The return value of G_read_raster3d_timestamp
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.READ_TIMESTAMP, RPCDefs.TYPE_RASTER3D,
         self.client_conn.send([RPCDefs.READ_TIMESTAMP, RPCDefs.TYPE_RASTER3D,
@@ -959,7 +1003,7 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def write_raster3d_timestamp(self, name, mapset, timestring):
     def write_raster3d_timestamp(self, name, mapset, timestring):
-        """!Write a file based 3D raster timetamp
+        """Write a file based 3D raster timetamp
 
 
            Please have a look at the documentation G_write_raster3d_timestamp
            Please have a look at the documentation G_write_raster3d_timestamp
            for the return values description.
            for the return values description.
@@ -967,10 +1011,10 @@ class CLibrariesInterface(object):
            Note:
            Note:
                Only timestamps of maps from the current mapset can written.
                Only timestamps of maps from the current mapset can written.
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @param timestring A GRASS datetime C-library compatible string
-           @return The return value of G_write_raster3d_timestamp
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :param timestring: A GRASS datetime C-library compatible string
+           :returns: The return value of G_write_raster3d_timestamp
         """
         """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.WRITE_TIMESTAMP, RPCDefs.TYPE_RASTER3D,
         self.client_conn.send([RPCDefs.WRITE_TIMESTAMP, RPCDefs.TYPE_RASTER3D,
@@ -978,11 +1022,11 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def vector_map_exists(self, name, mapset):
     def vector_map_exists(self, name, mapset):
-        """!Check if a vector map exists in the spatial database
+        """Check if a vector map exists in the spatial database
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return True if exists, False if not
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: True if exists, False if not
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.MAP_EXISTS, RPCDefs.TYPE_VECTOR,
         self.client_conn.send([RPCDefs.MAP_EXISTS, RPCDefs.TYPE_VECTOR,
@@ -990,12 +1034,12 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def read_vector_info(self, name, mapset):
     def read_vector_info(self, name, mapset):
-        """!Read the vector map info from the file system and store the content
+        """Read the vector map info from the file system and store the content
            into a dictionary
            into a dictionary
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @return The key value pairs of the map specific metadata, or None in case of an error
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :returns: The key value pairs of the map specific metadata, or None in case of an error
         """
         """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.READ_MAP_INFO, RPCDefs.TYPE_VECTOR,
         self.client_conn.send([RPCDefs.READ_MAP_INFO, RPCDefs.TYPE_VECTOR,
@@ -1003,12 +1047,12 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def has_vector_timestamp(self, name, mapset, layer=None):
     def has_vector_timestamp(self, name, mapset, layer=None):
-        """!Check if a file based vector timetamp exists
+        """Check if a file based vector timetamp exists
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @param layer The layer of the vector map
-           @return True if exists, False if not
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :param layer: The layer of the vector map
+           :returns: True if exists, False if not
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.HAS_TIMESTAMP, RPCDefs.TYPE_VECTOR,
         self.client_conn.send([RPCDefs.HAS_TIMESTAMP, RPCDefs.TYPE_VECTOR,
@@ -1016,15 +1060,15 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def remove_vector_timestamp(self, name, mapset, layer=None):
     def remove_vector_timestamp(self, name, mapset, layer=None):
-        """!Remove a file based vector timetamp
+        """Remove a file based vector timetamp
 
 
            Please have a look at the documentation G_remove_vector_timestamp
            Please have a look at the documentation G_remove_vector_timestamp
            for the return values description.
            for the return values description.
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @param layer The layer of the vector map
-           @return The return value of G_remove_vector_timestamp
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :param layer The layer of the vector map
+           :returns: The return value of G_remove_vector_timestamp
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.REMOVE_TIMESTAMP, RPCDefs.TYPE_VECTOR,
         self.client_conn.send([RPCDefs.REMOVE_TIMESTAMP, RPCDefs.TYPE_VECTOR,
@@ -1032,7 +1076,7 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def read_vector_timestamp(self, name, mapset, layer=None):
     def read_vector_timestamp(self, name, mapset, layer=None):
-        """!Read a file based vector timetamp
+        """Read a file based vector timetamp
 
 
            Please have a look at the documentation G_read_vector_timestamp
            Please have a look at the documentation G_read_vector_timestamp
            for the return values description.
            for the return values description.
@@ -1044,10 +1088,10 @@ class CLibrariesInterface(object):
 
 
            The end time may be None in case of a time instance.
            The end time may be None in case of a time instance.
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @param layer The layer of the vector map
-           @return The return value ofG_read_vector_timestamp and the timestamps
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :param layer: The layer of the vector map
+           :returns: The return value ofG_read_vector_timestamp and the timestamps
        """
        """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.READ_TIMESTAMP, RPCDefs.TYPE_VECTOR,
         self.client_conn.send([RPCDefs.READ_TIMESTAMP, RPCDefs.TYPE_VECTOR,
@@ -1055,7 +1099,7 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def write_vector_timestamp(self, name, mapset, timestring, layer=None):
     def write_vector_timestamp(self, name, mapset, timestring, layer=None):
-        """!Write a file based vector timetamp
+        """Write a file based vector timestamp
 
 
            Please have a look at the documentation G_write_vector_timestamp
            Please have a look at the documentation G_write_vector_timestamp
            for the return values description.
            for the return values description.
@@ -1063,11 +1107,11 @@ class CLibrariesInterface(object):
            Note:
            Note:
                Only timestamps pf maps from the current mapset can written.
                Only timestamps pf maps from the current mapset can written.
 
 
-           @param name The name of the map
-           @param mapset The mapset of the map
-           @param timestring A GRASS datetime C-library compatible string
-           @param layer The layer of the vector map
-           @return The return value of G_write_vector_timestamp
+           :param name: The name of the map
+           :param mapset: The mapset of the map
+           :param timestring: A GRASS datetime C-library compatible string
+           :param layer: The layer of the vector map
+           :returns: The return value of G_write_vector_timestamp
         """
         """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.WRITE_TIMESTAMP, RPCDefs.TYPE_VECTOR,
         self.client_conn.send([RPCDefs.WRITE_TIMESTAMP, RPCDefs.TYPE_VECTOR,
@@ -1075,20 +1119,47 @@ class CLibrariesInterface(object):
         return self.client_conn.recv()
         return self.client_conn.recv()
 
 
     def available_mapsets(self):
     def available_mapsets(self):
-        """!Return all available mapsets the user can access as a list of strings
-        
-           @param lock A multiprocessing.Lock instance
-           @param conn A multiprocessing.Pipe instance used to send True or False
-           @param data Can be None
+        """Return all available mapsets the user can access as a list of strings
            
            
-           @return Names of available mapsets as list of strings
+           :returns: Names of available mapsets as list of strings
         """
         """
         self._check_restart_server()
         self._check_restart_server()
         self.client_conn.send([RPCDefs.AVAILABLE_MAPSETS, ])
         self.client_conn.send([RPCDefs.AVAILABLE_MAPSETS, ])
         return self.client_conn.recv()
         return self.client_conn.recv()
+        
+    def get_driver_name(self, mapset=None):
+        """Return the temporal database driver of a specific mapset
+        
+           :param mapset: Name of the mapset
+           
+           :returns: Name of the driver or None if no temporal database present
+        """
+        if mapset is None or mapset is "":
+            mapset = corefunc.get_current_mapset()
 
 
+        self._check_restart_server()
+        self.client_conn.send([RPCDefs.GET_DRIVER_NAME, mapset])
+        return self.client_conn.recv()
+
+    def get_database_name(self, mapset=None):
+        """Return the temporal database name of a specific mapset
+        
+           :param mapset: Name of the mapset
+           
+           :returns: Name of the database or None if no temporal database present
+        """
+        
+        if mapset is None or mapset is "":
+            mapset = corefunc.get_current_mapset()
+        
+        self._check_restart_server()
+        self.client_conn.send([RPCDefs.GET_DATABASE_NAME, mapset])
+        return self.client_conn.recv()
+    
     def stop(self):
     def stop(self):
-        """!Stop the messenger server and close the pipe
+        """Stop the messenger server and close the pipe
+        
+           This method should be called at exit using the package atexit
         """
         """
         if self.server is not None and self.server.is_alive():
         if self.server is not None and self.server.is_alive():
             self.client_conn.send([0,])
             self.client_conn.send([0,])

+ 133 - 95
lib/python/temporal/core.py

@@ -1,6 +1,6 @@
-"""!@package grass.temporal
+"""package grass.temporal
 
 
-@brief GRASS Python scripting module (temporal GIS functions)
+GRASS Python scripting module (temporal GIS functions)
 
 
 Temporal GIS core functions to be used in library modules and scripts.
 Temporal GIS core functions to be used in library modules and scripts.
 
 
@@ -9,7 +9,6 @@ SQL database and to establish a connection to the database.
 
 
 Usage:
 Usage:
 
 
-@code
 
 
 >>> import grass.temporal as tgis
 >>> import grass.temporal as tgis
 >>> # Create the temporal database
 >>> # Create the temporal database
@@ -25,14 +24,13 @@ Usage:
 "SELECT name from raster_base where name = 'precipitation'"
 "SELECT name from raster_base where name = 'precipitation'"
 >>> dbif.close()
 >>> dbif.close()
 
 
-@endcode
 
 
 (C) 2011-2014 by the GRASS Development Team
 (C) 2011-2014 by the GRASS Development Team
 This program is free software under the GNU General Public
 This program is free software under the GNU General Public
 License (>=v2). Read the file COPYING that comes with GRASS
 License (>=v2). Read the file COPYING that comes with GRASS
 for details.
 for details.
 
 
-@author Soeren Gebbert
+:author: Soeren Gebbert
 """
 """
 import sys, traceback
 import sys, traceback
 import os
 import os
@@ -41,7 +39,7 @@ import locale
 import gettext
 import gettext
 gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'))
 gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'))
 
 
-import grass.script.core as core
+import grass.script.core as gcore
 from datetime import datetime
 from datetime import datetime
 from c_libraries_interface import *
 from c_libraries_interface import *
 # Import all supported database backends
 # Import all supported database backends
@@ -84,9 +82,9 @@ def profile_function(func):
 # It can either be "sqlite" or "pg"
 # It can either be "sqlite" or "pg"
 tgis_backend = None
 tgis_backend = None
 def get_tgis_backend():
 def get_tgis_backend():
-    """!Return the temporal GIS backend as string
+    """Return the temporal GIS backend as string
 
 
-       return either "sqlite" or "pg"
+       :returns: either "sqlite" or "pg"
     """
     """
     global tgis_backend
     global tgis_backend
     return tgis_backend
     return tgis_backend
@@ -95,7 +93,7 @@ def get_tgis_backend():
 # of the temporal GIS
 # of the temporal GIS
 tgis_database = None
 tgis_database = None
 def get_tgis_database():
 def get_tgis_database():
-    """!Return the temporal database string specified with t.connect
+    """Return the temporal database string specified with t.connect
     """
     """
     global tgis_database
     global tgis_database
     return tgis_database
     return tgis_database
@@ -114,9 +112,9 @@ tgis_db_version=2
 tgis_dbmi_paramstyle = None
 tgis_dbmi_paramstyle = None
 
 
 def get_tgis_dbmi_paramstyle():
 def get_tgis_dbmi_paramstyle():
-    """!Return the temporal database backend parameter style
+    """Return the temporal database backend parameter style
 
 
-       @return "qmark" or ""
+       :returns: "qmark" or ""
     """
     """
     global tgis_dbmi_paramstyle
     global tgis_dbmi_paramstyle
     return tgis_dbmi_paramstyle
     return tgis_dbmi_paramstyle
@@ -130,7 +128,7 @@ current_gisdbase = None
 ###############################################################################
 ###############################################################################
 
 
 def get_current_mapset():
 def get_current_mapset():
-    """!Return the current mapset
+    """Return the current mapset
 
 
        This is the fastest way to receive the current mapset.
        This is the fastest way to receive the current mapset.
        The current mapset is set by init() and stored in a global variable.
        The current mapset is set by init() and stored in a global variable.
@@ -142,7 +140,7 @@ def get_current_mapset():
 ###############################################################################
 ###############################################################################
 
 
 def get_current_location():
 def get_current_location():
-    """!Return the current location
+    """Return the current location
 
 
        This is the fastest way to receive the current location.
        This is the fastest way to receive the current location.
        The current location is set by init() and stored in a global variable.
        The current location is set by init() and stored in a global variable.
@@ -154,7 +152,7 @@ def get_current_location():
 ###############################################################################
 ###############################################################################
 
 
 def get_current_gisdbase():
 def get_current_gisdbase():
-    """!Return the current gis database (gisdbase)
+    """Return the current gis database (gisdbase)
 
 
        This is the fastest way to receive the current gisdbase.
        This is the fastest way to receive the current gisdbase.
        The current gisdbase is set by init() and stored in a global variable.
        The current gisdbase is set by init() and stored in a global variable.
@@ -181,7 +179,7 @@ enable_mapset_check = True
 enable_timestamp_write = True
 enable_timestamp_write = True
 
 
 def get_enable_mapset_check():
 def get_enable_mapset_check():
-    """!Return True if the mapsets should be checked while insert, updatem delete requests
+    """Return True if the mapsets should be checked while insert, update, delete requests
        and space time dataset registration.
        and space time dataset registration.
 
 
        If this global variable is set True, then maps can only be registered in space time datasets
        If this global variable is set True, then maps can only be registered in space time datasets
@@ -196,7 +194,7 @@ def get_enable_mapset_check():
     return enable_mapset_check
     return enable_mapset_check
 
 
 def get_enable_timestamp_write():
 def get_enable_timestamp_write():
-    """!Return True if the map timestamps should be written to the spatial database metadata as well.
+    """Return True if the map timestamps should be written to the spatial database metadata as well.
 
 
        If this global variable is set True, the timestamps of maps will be written as textfiles
        If this global variable is set True, the timestamps of maps will be written as textfiles
        for each map that will be inserted or updated in the temporal database using the C-library
        for each map that will be inserted or updated in the temporal database using the C-library
@@ -218,9 +216,9 @@ def get_enable_timestamp_write():
 message_interface=None
 message_interface=None
 
 
 def _init_tgis_message_interface(raise_on_error=False):
 def _init_tgis_message_interface(raise_on_error=False):
-    """!Initiate the global mesage interface
+    """Initiate the global mesage interface
 
 
-       @param raise_on_error If True raise a FatalError exception in case of a fatal error,
+       :param raise_on_error: If True raise a FatalError exception in case of a fatal error,
                              call sys.exit(1) otherwise
                              call sys.exit(1) otherwise
     """
     """
     global message_interface
     global message_interface
@@ -228,7 +226,7 @@ def _init_tgis_message_interface(raise_on_error=False):
     message_interface = messages.get_msgr(raise_on_error=raise_on_error)
     message_interface = messages.get_msgr(raise_on_error=raise_on_error)
 
 
 def get_tgis_message_interface():
 def get_tgis_message_interface():
-    """!Return the temporal GIS message interface which is of type
+    """Return the temporal GIS message interface which is of type
        grass.pyhrass.message.Messenger()
        grass.pyhrass.message.Messenger()
 
 
        Use this message interface to print messages to stdout using the
        Use this message interface to print messages to stdout using the
@@ -245,7 +243,7 @@ def get_tgis_message_interface():
 c_library_interface=None
 c_library_interface=None
 
 
 def _init_tgis_c_library_interface():
 def _init_tgis_c_library_interface():
-    """!Set the global C-library interface variable that
+    """Set the global C-library interface variable that
        provides a fast and exit safe interface to the C-library libgis,
        provides a fast and exit safe interface to the C-library libgis,
        libraster, libraster3d and libvector functions
        libraster, libraster3d and libvector functions
     """
     """
@@ -253,7 +251,7 @@ def _init_tgis_c_library_interface():
     c_library_interface = CLibrariesInterface()
     c_library_interface = CLibrariesInterface()
 
 
 def get_tgis_c_library_interface():
 def get_tgis_c_library_interface():
-    """!Return the C-library interface that
+    """Return the C-library interface that
        provides a fast and exit safe interface to the C-library libgis,
        provides a fast and exit safe interface to the C-library libgis,
        libraster, libraster3d and libvector functions
        libraster, libraster3d and libvector functions
     """
     """
@@ -267,15 +265,14 @@ def get_tgis_c_library_interface():
 raise_on_error = False
 raise_on_error = False
 
 
 def set_raise_on_error(raise_exp=True):
 def set_raise_on_error(raise_exp=True):
-    """!Define behavior on fatal error, invoked using the tgis messenger
+    """Define behavior on fatal error, invoked using the tgis messenger
     interface (msgr.fatal())
     interface (msgr.fatal())
 
 
     The messenger interface will be restarted using the new error policy
     The messenger interface will be restarted using the new error policy
 
 
-    @param raise_exp True to raise a FatalError exception instead of calling
-    sys.exit(1) when using the tgis messenger interface
+    :param raise_exp: True to raise a FatalError exception instead of calling
+                      sys.exit(1) when using the tgis messenger interface
 
 
-    @code
 
 
     >>> import grass.temporal as tgis
     >>> import grass.temporal as tgis
     >>> tgis.init()
     >>> tgis.init()
@@ -297,9 +294,8 @@ def set_raise_on_error(raise_exp=True):
         raise FatalError(message)
         raise FatalError(message)
     FatalError: Ohh no no no!
     FatalError: Ohh no no no!
 
 
-    @endcode
 
 
-    @return current status
+    :returns: current status
     """
     """
     global raise_on_error
     global raise_on_error
     tmp_raise = raise_on_error
     tmp_raise = raise_on_error
@@ -315,7 +311,7 @@ def set_raise_on_error(raise_exp=True):
 
 
 
 
 def get_raise_on_error():
 def get_raise_on_error():
-    """!Return True if a FatalError exception is raised instead of calling
+    """Return True if a FatalError exception is raised instead of calling
        sys.exit(1) in case a fatal error was invoked with msgr.fatal()
        sys.exit(1) in case a fatal error was invoked with msgr.fatal()
     """
     """
     global raise_on_error
     global raise_on_error
@@ -325,8 +321,8 @@ def get_raise_on_error():
 ###############################################################################
 ###############################################################################
 
 
 def get_tgis_version():
 def get_tgis_version():
-    """!Get the verion number of the temporal framework
-       @return The version number of the temporal framework as string
+    """Get the version number of the temporal framework
+       :returns: The version number of the temporal framework as string
     """
     """
     global tgis_version
     global tgis_version
     return tgis_version
     return tgis_version
@@ -334,8 +330,8 @@ def get_tgis_version():
 ###############################################################################
 ###############################################################################
 
 
 def get_tgis_db_version():
 def get_tgis_db_version():
-    """!Get the verion number of the temporal framework
-       @return The version number of the temporal framework as string
+    """Get the version number of the temporal framework
+       :returns: The version number of the temporal framework as string
     """
     """
     global tgis_db_version
     global tgis_db_version
     return tgis_db_version
     return tgis_db_version
@@ -343,11 +339,11 @@ def get_tgis_db_version():
 ###############################################################################
 ###############################################################################
 
 
 def get_tgis_metadata(dbif=None):
 def get_tgis_metadata(dbif=None):
-    """!Return the tgis metadata table as a list of rows (dicts)
+    """Return the tgis metadata table as a list of rows (dicts)
                or None if not present
                or None if not present
 
 
-       @param dbif The database interface to be used
-       @return The selected rows with key/value comumns or None
+       :param dbif: The database interface to be used
+       :returns: The selected rows with key/value columns or None
     """
     """
 
 
     dbif, connected = init_dbif(dbif)
     dbif, connected = init_dbif(dbif)
@@ -372,7 +368,7 @@ def get_tgis_metadata(dbif=None):
 tgis_database_string = None
 tgis_database_string = None
 
 
 def get_tgis_database_string():
 def get_tgis_database_string():
-    """!Return the preprocessed temporal database string
+    """Return the preprocessed temporal database string
 
 
        This string is the temporal database string set with t.connect
        This string is the temporal database string set with t.connect
        that was processed to substitue location, gisdbase and mapset
        that was processed to substitue location, gisdbase and mapset
@@ -391,7 +387,7 @@ def get_sql_template_path():
 ###############################################################################
 ###############################################################################
 
 
 def stop_subprocesses():
 def stop_subprocesses():
-    """!Stop the messenger and C-interface subprocesses
+    """Stop the messenger and C-interface subprocesses
        that are started by tgis.init()
        that are started by tgis.init()
     """
     """
     global message_interface
     global message_interface
@@ -407,7 +403,7 @@ atexit.register(stop_subprocesses)
 ###############################################################################
 ###############################################################################
 
 
 def init(raise_fatal_error=False):
 def init(raise_fatal_error=False):
-    """!This function set the correct database backend from GRASS environmental variables
+    """This function set the correct database backend from GRASS environmental variables
        and creates the grass temporal database structure for raster,
        and creates the grass temporal database structure for raster,
        vector and raster3d maps as well as for the space-time datasets strds,
        vector and raster3d maps as well as for the space-time datasets strds,
        str3ds and stvds in case it does not exists.
        str3ds and stvds in case it does not exists.
@@ -422,7 +418,7 @@ def init(raise_fatal_error=False):
        - TGIS_DISABLE_MAPSET_CHECK
        - TGIS_DISABLE_MAPSET_CHECK
        - TGIS_DISABLE_TIMESTAMP_WRITE
        - TGIS_DISABLE_TIMESTAMP_WRITE
 
 
-       Re-run the script if the following t.connect variables change while the process runs:
+       Re-run this function if the following t.connect variables change while the process runs:
        - temporal GIS driver (set by t.connect driver=)
        - temporal GIS driver (set by t.connect driver=)
        - temporal GIS database (set by t.connect database=)
        - temporal GIS database (set by t.connect database=)
 
 
@@ -433,7 +429,7 @@ def init(raise_fatal_error=False):
         ATTENTION: This functions must be called before any spatio-temporal processing
         ATTENTION: This functions must be called before any spatio-temporal processing
                    can be started
                    can be started
 
 
-        @param raise_fatal_error Set this True to assure that the init() function
+        :param raise_fatal_error: Set this True to assure that the init() function
                                  does not kill a persistent process like the GUI.
                                  does not kill a persistent process like the GUI.
 
 
                                  If set True a grass.pygrass.messages.FatalError
                                  If set True a grass.pygrass.messages.FatalError
@@ -457,9 +453,8 @@ def init(raise_fatal_error=False):
 
 
     # We must run t.connect at first to create the temporal database and to
     # We must run t.connect at first to create the temporal database and to
     # get the environmental variables
     # get the environmental variables
-    core.run_command("t.connect", flags="c")
-    kv = core.parse_command("t.connect", flags="pg")
-    grassenv = core.gisenv()
+    gcore.run_command("t.connect", flags="c")
+    grassenv = gcore.gisenv()
 
 
     # Set the global variable for faster access
     # Set the global variable for faster access
     current_mapset = grassenv["MAPSET"]
     current_mapset = grassenv["MAPSET"]
@@ -472,7 +467,7 @@ def init(raise_fatal_error=False):
 
 
     # Check if the script library raises on error,
     # Check if the script library raises on error,
     # if so we do the same
     # if so we do the same
-    if core.get_raise_on_error() is True:
+    if gcore.get_raise_on_error() is True:
         raise_on_error = True
         raise_on_error = True
 
 
     # Start the GRASS message interface server
     # Start the GRASS message interface server
@@ -481,6 +476,10 @@ def init(raise_fatal_error=False):
     _init_tgis_c_library_interface()
     _init_tgis_c_library_interface()
     msgr = get_tgis_message_interface()
     msgr = get_tgis_message_interface()
     msgr.debug(1, "Initiate the temporal database")
     msgr.debug(1, "Initiate the temporal database")
+    
+    ciface = get_tgis_c_library_interface()
+    driver_string = ciface.get_driver_name()
+    database_string = ciface.get_database_name()
 
 
     # Set the mapset check and the timestamp write
     # Set the mapset check and the timestamp write
     if grassenv.has_key("TGIS_DISABLE_MAPSET_CHECK"):
     if grassenv.has_key("TGIS_DISABLE_MAPSET_CHECK"):
@@ -493,17 +492,17 @@ def init(raise_fatal_error=False):
             enable_timestamp_write = False
             enable_timestamp_write = False
             msgr.warning("TGIS_DISABLE_TIMESTAMP_WRITE is True")
             msgr.warning("TGIS_DISABLE_TIMESTAMP_WRITE is True")
 
 
-    if "driver" in kv:
-        if kv["driver"] == "sqlite":
-            tgis_backend = kv["driver"]
+    if driver_string is not None and driver_string is not "":
+        if driver_string == "sqlite":
+            tgis_backend = driver_string
             try:
             try:
                 import sqlite3
                 import sqlite3
             except ImportError:
             except ImportError:
                 msgr.error("Unable to locate the sqlite SQL Python interface module sqlite3.")
                 msgr.error("Unable to locate the sqlite SQL Python interface module sqlite3.")
                 raise
                 raise
             dbmi = sqlite3
             dbmi = sqlite3
-        elif kv["driver"] == "pg":
-            tgis_backend = kv["driver"]
+        elif driver_string == "pg":
+            tgis_backend = driver_string
             try:
             try:
                 import psycopg2
                 import psycopg2
             except ImportError:
             except ImportError:
@@ -516,26 +515,15 @@ def init(raise_fatal_error=False):
             dbmi = sqlite3
             dbmi = sqlite3
     else:
     else:
         # Set the default sqlite3 connection in case nothing was defined
         # Set the default sqlite3 connection in case nothing was defined
-        core.run_command("t.connect", flags="d")
-        kv = core.parse_command("t.connect", flags="pg")
-        tgis_backend = kv["driver"]
+        gcore.run_command("t.connect", flags="d")
+        driver_string = ciface.get_driver_name()
+        database_string = ciface.get_database_name()
+        tgis_backend = driver_string
 
 
-    # Database string from t.connect -pg
-    tgis_database = kv["database"]
+    tgis_database_string = database_string
     # Set the parameter style
     # Set the parameter style
     tgis_dbmi_paramstyle = dbmi.paramstyle
     tgis_dbmi_paramstyle = dbmi.paramstyle
 
 
-    # Create the temporal database string
-    if tgis_backend == "sqlite":
-        # We substitute GRASS variables if they are located in the database string
-        # This behavior is in conjunction with db.connect
-        tgis_database_string = tgis_database
-        tgis_database_string = tgis_database_string.replace("$GISDBASE", current_gisdbase)
-        tgis_database_string = tgis_database_string.replace("$LOCATION_NAME", current_location)
-        tgis_database_string = tgis_database_string.replace("$MAPSET", current_mapset)
-    elif tgis_backend == "pg":
-        tgis_database_string = tgis_database
-
     # We do not know if the database already exists
     # We do not know if the database already exists
     db_exists = False
     db_exists = False
     dbif = SQLDatabaseInterfaceConnection()
     dbif = SQLDatabaseInterfaceConnection()
@@ -608,12 +596,12 @@ def get_database_info_string():
 ###############################################################################
 ###############################################################################
 
 
 def create_temporal_database(dbif):
 def create_temporal_database(dbif):
-    """!This function will create the temporal database
+    """This function will create the temporal database
 
 
        It will create all tables and triggers that are needed to run
        It will create all tables and triggers that are needed to run
        the temporal GIS
        the temporal GIS
 
 
-       @param dbif The database interface to be used
+       :param dbif: The database interface to be used
     """
     """
     global tgis_backend
     global tgis_backend
     global tgis_version
     global tgis_version
@@ -766,7 +754,7 @@ def _create_tgis_metadata_table(content, dbif=None):
 ###############################################################################
 ###############################################################################
 
 
 class SQLDatabaseInterfaceConnection():
 class SQLDatabaseInterfaceConnection():
-    """!This class represents the database interface connection
+    """This class represents the database interface connection
        and provides access to the chisen backend modules.
        and provides access to the chisen backend modules.
 
 
        The following DBMS are supported:
        The following DBMS are supported:
@@ -775,6 +763,13 @@ class SQLDatabaseInterfaceConnection():
 
 
     """
     """
     def __init__(self):
     def __init__(self):
+        """TODO:
+           Create a list of all accessible mapsets that have temporal database definitions
+           Create a database connection for each mapset, reuse existing database connections
+           in case the connection specifications are identical (a single temporal database).
+           
+           Database string and river are mapset specific, hence the driver may change with the mapset.
+        """
         self.connected = False
         self.connected = False
         global tgis_backend
         global tgis_backend
         if tgis_backend == "sqlite":
         if tgis_backend == "sqlite":
@@ -786,6 +781,10 @@ class SQLDatabaseInterfaceConnection():
         self.msgr.debug(1, "SQLDatabaseInterfaceConnection constructor")
         self.msgr.debug(1, "SQLDatabaseInterfaceConnection constructor")
 
 
     def __del__(self):
     def __del__(self):
+        """TODO:
+           Close all mapset specific connections, be aware that different 
+           mapsets may have identical connections.
+        """
         if self.connected is True:
         if self.connected is True:
             self.close()
             self.close()
 
 
@@ -801,9 +800,15 @@ class SQLDatabaseInterfaceConnection():
                 self.connection.rollback()
                 self.connection.rollback()
 
 
     def connect(self):
     def connect(self):
-        """!Connect to the DBMI to execute SQL statements
+        """Connect to the DBMI to execute SQL statements
 
 
            Supported backends are sqlite3 and postgresql
            Supported backends are sqlite3 and postgresql
+           
+           TODO:
+           Create connections for each mapset that has a temporal database.
+           Open existing connections only once.
+           The dbmi, connection and cursor are mapset specific 
+           and must be managed in a dict.
         """
         """
         global tgis_database_string
         global tgis_database_string
 
 
@@ -824,36 +829,45 @@ class SQLDatabaseInterfaceConnection():
             self.connected = True
             self.connected = True
         except Exception as e:
         except Exception as e:
             self.msgr.fatal(_("Unable to connect to %(db)s database: "
             self.msgr.fatal(_("Unable to connect to %(db)s database: "
-                                       "%(string)s\nException: \"%(ex)s\"\nPlease use t.connect to set a "
-                                       "read- and writable temporal database backend")%({"db":self.dbmi.__name__, 
-                                                                                                                      "string":tgis_database_string, 
-                                                                                                                      "ex":e,  }))
+                               "%(string)s\nException: \"%(ex)s\"\nPlease use t.connect to set a "
+                               "read- and writable temporal database backend")%({"db":self.dbmi.__name__, 
+                                                                                 "string":tgis_database_string, 
+                                                                                 "ex":e,}))
 
 
     def close(self):
     def close(self):
-        """!Close the DBMI connection"""
+        """Close the DBMI connection
+           TODO:
+           There may be several temporal databases in a location, hence 
+           close all temporal databases that have been opened. Use a dictionary
+           to manage different connections.
+           
+        """
         self.connection.commit()
         self.connection.commit()
         self.cursor.close()
         self.cursor.close()
         self.connected = False
         self.connected = False
 
 
-    def mogrify_sql_statement(self, content):
-        """!Return the SQL statement and arguments as executable SQL string
+    def mogrify_sql_statement(self, content, mapset=None):
+        """Return the SQL statement and arguments as executable SQL string
+        
+           TODO:
+           Use the mapset argument to identify the correct database driver
 
 
-           @param content The content as tuple with two entries, the first
+           :param content: The content as tuple with two entries, the first
                            entry is the SQL statement with DBMI specific
                            entry is the SQL statement with DBMI specific
                            place holder (?), the second entry is the argument
                            place holder (?), the second entry is the argument
-                           list that should substitue the place holder.
+                           list that should substitute the place holder.
+           :param mapset: The mapset of the abstract dataset or temporal
+                          database location, if None the current mapset 
+                          will be used
 
 
            Usage:
            Usage:
 
 
-           @code
 
 
            >>> init()
            >>> init()
            >>> dbif = SQLDatabaseInterfaceConnection()
            >>> dbif = SQLDatabaseInterfaceConnection()
            >>> dbif.mogrify_sql_statement(["SELECT ctime FROM raster_base WHERE id = ?",
            >>> dbif.mogrify_sql_statement(["SELECT ctime FROM raster_base WHERE id = ?",
            ... ["soil@PERMANENT",]])
            ... ["soil@PERMANENT",]])
            "SELECT ctime FROM raster_base WHERE id = 'soil@PERMANENT'"
            "SELECT ctime FROM raster_base WHERE id = 'soil@PERMANENT'"
-
-           @endcode
         """
         """
         sql = content[0]
         sql = content[0]
         args = content[1]
         args = content[1]
@@ -913,11 +927,18 @@ class SQLDatabaseInterfaceConnection():
 
 
                 return statement
                 return statement
 
 
-    def check_table(self, table_name):
-        """!Check if a table exists in the temporal database
-
-           @param table_name The name of the table to be checked for existance
-           @return True if the table exists, False otherwise
+    def check_table(self, table_name, mapset=None):
+        """Check if a table exists in the temporal database
+
+           :param table_name: The name of the table to be checked for existence
+           :param mapset: The mapset of the abstract dataset or temporal
+                          database location, if None the current mapset 
+                          will be used
+           :returns: True if the table exists, False otherwise
+           
+           TODO:
+           There may be several temporal databases in a location, hence 
+           the mapset is used to query the correct temporal database.
         """
         """
         table_exists = False
         table_exists = False
         connected = False
         connected = False
@@ -943,14 +964,32 @@ class SQLDatabaseInterfaceConnection():
             self.close()
             self.close()
 
 
         return table_exists
         return table_exists
+    
+    def execute(self, statement, mapset=None):
+        """Execute a SQL statement
+
+           :param statement: The executable SQL statement or SQL script
+           :param mapset: The mapset of the abstract dataset or temporal
+                          database location, if None the current mapset 
+                          will be used
+           
+           NOTE: not implemented, the purpose of this function is to
+                 replace all dbif.cursor.execute() calls in the temporal
+                 framework to allow SQL statement execution with distributed
+                 temporal databases identified by their mapset name
+        """
+        pass
 
 
-    def execute_transaction(self, statement):
-        """!Execute a transactional SQL statement
+    def execute_transaction(self, statement, mapset=None):
+        """Execute a transactional SQL statement
 
 
-            The BEGIN and END TRANSACTION statements will be added automatically
-            to the sql statement
+           The BEGIN and END TRANSACTION statements will be added automatically
+           to the sql statement
 
 
-            @param statement The executable SQL statement or SQL script
+           :param statement: The executable SQL statement or SQL script
+           :param mapset: The mapset of the abstract dataset or temporal
+                          database location, if None the current mapset 
+                          will be used
         """
         """
         connected = False
         connected = False
         if not self.connected:
         if not self.connected:
@@ -980,14 +1019,14 @@ class SQLDatabaseInterfaceConnection():
 ###############################################################################
 ###############################################################################
 
 
 def init_dbif(dbif):
 def init_dbif(dbif):
-    """!This method checks if the database interface connection exists,
+    """This method checks if the database interface connection exists,
         if not a new one will be created, connected and True will be returned.
         if not a new one will be created, connected and True will be returned.
         If the database interface exists but is connected, the connection will be established.
         If the database interface exists but is connected, the connection will be established.
 
 
-        @return the tuple (dbif, True|False)
+        :returns: the tuple (dbif, True|False)
 
 
         Usage code sample:
         Usage code sample:
-        @code
+  
 
 
         dbif, connect = tgis.init_dbif(None)
         dbif, connect = tgis.init_dbif(None)
 
 
@@ -998,7 +1037,6 @@ def init_dbif(dbif):
         if connect:
         if connect:
             dbif.close()
             dbif.close()
 
 
-        @endcode
     """
     """
     if dbif is None:
     if dbif is None:
         dbif = SQLDatabaseInterfaceConnection()
         dbif = SQLDatabaseInterfaceConnection()