-
-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grass.pygrass: VisibleMapset: fix reading search path #2584
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and work as expected.
It requires modifying the |
Complex test with 3c8d6b8:
It seems that with this last test example (Python code output) we have an extra unnecessary empty
|
python/grass/pygrass/gis/__init__.py
Outdated
self._write(lns) | ||
return lns | ||
try: | ||
with open(self.spath, "rb") as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open
file func mode
param arg should be "r"
only according output bellow and we don't need decode readed lines:
GRASS nc_spm_08_grass7/landsat:~ > g.mapsets operation=set mapset=landsat
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
Same for _write()
method, open
file func with mode
param arg should be w
only.
def _write(self, mapsets):
"""Write to SEARCH_PATH file the changes in the search path
:param list mapsets: a list of mapset's names
"""
with open(self.spath, "w") as f:
f.write("\n".join([m for m in mapsets if m in self.location.mapsets()]))
extend()
method without decode
func
def extend(self, mapsets):
"""Add more mapsets to the search path
:param list mapsets: a list of mapset's names
"""
final = self.read()
final.extend(
[
m
for m in mapsets
if m in self.location.mapsets() and m not in final
]
)
self._write(final)
python/grass/pygrass/gis/__init__.py
Outdated
f.write(b"\n".join([encode(m) for m in mapsets if m in ms])) | ||
with open(self.spath, "w") as f: | ||
ms = self.location.mapsets() | ||
f.write("\n".join([m for m in mapsets if m in ms])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small note (it is not bug):
g.mapsets
module write \n
on the EOF for every line in the SEARCH_PATH file:
GRASS nc_spm_08_grass7/landsat:~ > g.mapsets operation=set mapset=landsat
GRASS nc_spm_08_grass7/landsat:~ > g.mapsets operation=add mapset=PERMANENT
GRASS nc_spm_08_grass7/landsat:~ > cat -e grassdata/nc_spm_08_grass7/landsat/SEARCH_PATH
landsat$
PERMANENT$
VisibleMapset
class instance _write
method do not write \n
on the EOF on the last line in the SEARCH_PATH file:
GRASS nc_spm_08_grass7/landsat:~ > g.mapsets -l
Available mapsets:
PERMANENT climate_2000_2012 landsat tomas
GRASS nc_spm_08_grass7/landsat:~ > cat /tmp/test.py
#!/usr/bin/env python3
import sys
from grass.pygrass.gis import VisibleMapset
def main():
vm = VisibleMapset(mapset=sys.argv[1])
vm.extend(["climate_2000_2012", "tomas"])
print(vm.read())
if __name__ == '__main__':
main()
GRASS nc_spm_08_grass7/landsat:~ > python /tmp/test.py $(g.gisenv get="MAPSET")
['landsat', 'PERMANENT', 'climate_2000_2012', 'tomas']
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:~ >
tomasGRASS nc_spm_08_grass7/landsat:~ >
this line should be (missing $
which is \n
)
tomas$
GRASS nc_spm_08_grass7/landsat:~ >
Fixed with (line 459):
eof = "\n"
f.write(eof.join([m for m in mapsets if m in ms]) + eof)
and (line 469):
f.write("%s\n" % mapset)
With PR #2586 I solve problem with additional empty line (
should be
Example when
should be
this line
|
Could we move forward with this PR, please? |
* handle missing search path file, do not write since this is only reading * use text mode for writing/reading * write newline after each mapset
* handle missing search path file, do not write since this is only reading * use text mode for writing/reading * write newline after each mapset
* handle missing search path file, do not write since this is only reading * use text mode for writing/reading * write newline after each mapset
* handle missing search path file, do not write since this is only reading * use text mode for writing/reading * write newline after each mapset
* handle missing search path file, do not write since this is only reading * use text mode for writing/reading * write newline after each mapset
VisibleMapset class was not reading search path properly, instead it was always just writing PERMANENT only into the path.