grass
grass copied to clipboard
grass.pygrass: VisibleMapset: fix reading search path
VisibleMapset class was not reading search path properly, instead it was always just writing PERMANENT only into the path.
It requires modifying the GridModule class tests.
Complex test with https://github.com/OSGeo/grass/pull/2584/commits/3c8d6b851383782774ad69abb8a40c346e8d1f03:
- SEARCH_PATH file doesn't exists (passed):
GRASS nc_spm_08_grass7/landsat:~ > file grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH
grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH: cannot open `grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH' (No such file or directory)
GRASS nc_spm_08_grass7/landsat:~ > g.mapsets -p
Accessible mapsets:
landsat PERMANENT
GRASS nc_spm_08_grass7/landsat:~ > cat /tmp/visible_mapset_test.py
#!/usr/bin/env python3
import sys
from grass.pygrass.gis import VisibleMapset
def main():
vm = VisibleMapset(mapset=sys.argv[1])
print(vm.read())
if __name__ == '__main__':
main()
GRASS nc_spm_08_grass7/landsat:~ > python /tmp/visible_mapset_test.py $(g.gisenv get="MAPSET")
['landsat', 'PERMANENT']
- SEARCH_PATH file is empty (passed):
GRASS nc_spm_08_grass7/landsat:~ > file grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH
grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH: empty
GRASS nc_spm_08_grass7/landsat:~ > g.mapsets -p
Accessible mapsets:
landsat
GRASS nc_spm_08_grass7/landsat:~ > python /tmp/visible_mapset_test.py $(g.gisenv get="MAPSET")
['landsat']
- SEARCH_PATH file exist (passed, and a new bug appear with
g.mapsetsmodule):
GRASS nc_spm_08_grass7/landsat:~ > file grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH
grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH: ASCII text
GRASS nc_spm_08_grass7/landsat:~ > cat grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH
landsat
PERMANENT
climate_2000_2012
GRASS nc_spm_08_grass7/landsat:~ > python /tmp/visible_mapset_test.py $(g.gisenv get="MAPSET")
['landsat', 'PERMANENT', 'climate_2000_2012', '']
It seems that with this last test example (Python code output) we have an extra unnecessary empty '' MAPSET name due the g.mapsets module writing an extra \n to the SEARCH_PATH file. PR #2586.
GRASS nc_spm_08_grass7/landsat:~ > cat -e grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH
landsat$
PERMANENT$
climate_2000_2012$
$
No I got confused, didn't you @tmszi change the behavior of g.mapsets in #2586 to avoid writing the newline at the end? Should I revert the last commit in this PR?
No I got confused, didn't you @tmszi change the behavior of g.mapsets in #2586 to avoid writing the newline at the end? Should I revert the last commit in this PR?
With PR #2586 I solve problem with additional empty line ($ == \n) when g.mapsets module write to the SEARCH_PATH file.
GRASS nc_spm_08_grass7/landsat:~ > cat -e grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH
landsat$
PERMANENT$
climate_2000_2012$
$
should be
GRASS nc_spm_08_grass7/landsat:~ > cat -e grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH
landsat$
PERMANENT$
climate_2000_2012$
VisibleMapset class instance _write() method don't write \n on the last line ($ == \n) MAPSET -> MAPSET\n and your last commit https://github.com/OSGeo/grass/pull/2584/commits/a3e05df77ee9d59e9dc66938459e2e21faec1937 solve it and is needed:
Example when _write() method write to SEARCH_PATH file:
GRASS nc_spm_08_grass7/landsat:~ > cat -e grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH
landsat$
PERMANENT$
climate_2000_2012$
tomasGRASS nc_spm_08_grass7/landsat:~ >
should be
GRASS nc_spm_08_grass7/landsat:~ > cat -e grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH
landsat$
PERMANENT$
climate_2000_2012$
tomas$
GRASS nc_spm_08_grass7/landsat:~ >
this line tomasGRASS nc_spm_08_grass7/landsat:~ > should be (missing \n on the EOF tomas to tomas$)
tomas$
GRASS nc_spm_08_grass7/landsat:~ >
Could we move forward with this PR, please?