grass icon indicating copy to clipboard operation
grass copied to clipboard

grass.pygrass: VisibleMapset: fix reading search path

Open petrasovaa opened this issue 3 years ago • 2 comments
trafficstars

VisibleMapset class was not reading search path properly, instead it was always just writing PERMANENT only into the path.

petrasovaa avatar Sep 19 '22 15:09 petrasovaa

It requires modifying the GridModule class tests.

tmszi avatar Sep 19 '22 18:09 tmszi

Complex test with https://github.com/OSGeo/grass/pull/2584/commits/3c8d6b851383782774ad69abb8a40c346e8d1f03:

  1. 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']
  1. 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']
  1. SEARCH_PATH file exist (passed, and a new bug appear with g.mapsets module):
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$
$

tmszi avatar Sep 20 '22 04:09 tmszi

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?

petrasovaa avatar Sep 23 '22 09:09 petrasovaa

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:~ >

tmszi avatar Sep 23 '22 18:09 tmszi

Could we move forward with this PR, please?

tmszi avatar Oct 04 '22 04:10 tmszi