diff --git a/python/grass/script/core.py b/python/grass/script/core.py index 672284713a3..0534a1ce5b3 100644 --- a/python/grass/script/core.py +++ b/python/grass/script/core.py @@ -1326,13 +1326,30 @@ def del_temp_region(): def find_file(name, element="cell", mapset=None, env=None): """Returns the output from running g.findfile as a - dictionary. Example: + dictionary. + + Elements in g.findfile refer to mapset directories. However, in + parts of the code, different element terms like rast, raster, or rast3d + are used. For convenience the function translates such element types + to respective mapset elements. Current translations are: + "rast": "cell", + "raster": "cell", + "rast3d": "grid3", + "raster3d": "grid3", + "raster_3d": "grid3", + + Example: >>> result = find_file('elevation', element='cell') >>> print(result['fullname']) elevation@PERMANENT >>> print(result['file']) # doctest: +ELLIPSIS /.../PERMANENT/cell/elevation + >>> result = find_file('elevation', element='raster') + >>> print(result['fullname']) + elevation@PERMANENT + >>> print(result['file']) # doctest: +ELLIPSIS + /.../PERMANENT/cell/elevation :param str name: file name @@ -1342,11 +1359,19 @@ def find_file(name, element="cell", mapset=None, env=None): :return: parsed output of g.findfile """ - if element == "raster" or element == "rast": - verbose(_('Element type should be "cell" and not "%s"') % element) - element = "cell" + element_translation = { + "rast": "cell", + "raster": "cell", + "rast3d": "grid3", + "raster3d": "grid3", + "raster_3d": "grid3", + } + + if element in element_translation: + element = element_translation[element] + # g.findfile returns non-zero when file was not found - # se we ignore return code and just focus on stdout + # so we ignore return code and just focus on stdout process = start_command( "g.findfile", flags="n",