Hi Developers,
I'm working on a grass add-ons... as r.modis I've split the module
interface from the libraries, so as r,modis I have to add a piece of
code to append the libraries to the python path, see the example
below:
{{{
libmodis = None
if os.path.isdir(os.path.join(os.getenv('GISBASE'), 'etc', 'r.modis')):
libmodis = os.path.join(os.getenv('GISBASE'), 'etc', 'r.modis')
elif os.getenv('GRASS_ADDON_BASE') and \
os.path.isdir(os.path.join(os.getenv('GRASS_ADDON_BASE'), 'etc',
'r.modis')):
libmodis = os.path.join(os.getenv('GRASS_ADDON_BASE'), 'etc', 'r.modis')
elif os.path.isdir(os.path.join('..', 'libmodis')):
libmodis = os.path.join('..', 'libmodis')
if not libmodis:
sys.exit("ERROR: modis library not found")
}}}
My idea is to transform this operation into a function, that return
the path, None if the path is not found, therefore the code above will
become something like:
{{{
from grass.pygrass.functions import get_lib_path
libmodis = get_lib_path(modname='r.modis', libname='libmodis')
if libmodis is None:
sys.exit("ERROR: modis library not found")
sys.path.append(libmodis)
}}}
In this way we avoid to have the same fragment of code sparse in the
grass code...
Should I put this function in grass.script.core?
Do you have any better function name?
Do you have any particular advice?
Best regards
Pietro