Exemplo n.º 1
0
def _get_mapset(lock, conn, data):
    """Return the current 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]

       :returns: Name of the current mapset
    """
    mapset = libgis.G_mapset()
    conn.send(mapset)
Exemplo n.º 2
0
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
    """
    mapset = data[1]
    if not mapset:
        mapset = libgis.G_mapset()
    dbstring = libtgis.tgis_get_mapset_database_name(mapset)

    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", libgis.G_gisdbase())
        dbstring = dbstring.replace("$LOCATION_NAME", libgis.G_location())
        dbstring = dbstring.replace("$MAPSET", libgis.G_mapset())
    conn.send(dbstring)
Exemplo n.º 3
0
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 mapset as list entry 1 [function_id, mapset]

       :returns: Name of the driver or None if no temporal database present
    """
    mapset = data[1]
    if not mapset:
        mapset = libgis.G_mapset()

    drstring = libtgis.tgis_get_mapset_driver_name(mapset)
    conn.send(drstring)
Exemplo n.º 4
0
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()

    count = 0
    mapset_list = []
    while mapsets[count]:
        char_list = ""
        mapset = mapsets[count]
        if libgis.G__mapset_permissions(mapset) > 0:
            count += 1
            c = 0
            while mapset[c] != "\x00":
                char_list += mapset[c]
                c += 1

        mapset_list.append(char_list)

    # We need to sort the mapset list, but the first one should be
    # the current mapset
    current_mapset = libgis.G_mapset()
    mapset_list.remove(current_mapset)
    mapset_list.sort()
    mapset_list.reverse()
    mapset_list.append(current_mapset)
    mapset_list.reverse()

    conn.send(mapset_list)
Exemplo n.º 5
0
 def wrapper(self, *args, **kargs):
     if self.mapset == libgis.G_mapset().decode():
         return method(self, *args, **kargs)
     else:
         raise GrassError(_("Map <{}> not found in current mapset").format(
             self.name))