[GRASS-SVN] r58208 - in grass-addons/grass7/raster/r.modis: r.modis.download r.modis.import

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 13 08:04:05 PST 2013


Author: wenzeslaus
Date: 2013-11-13 08:04:04 -0800 (Wed, 13 Nov 2013)
New Revision: 58208

Modified:
   grass-addons/grass7/raster/r.modis/r.modis.download/r.modis.download.py
   grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py
Log:
r.modis: using get_lib_path function to find the library

tested for r.modis modules installed as addons with r.modis/r.modis directory in GRASS_ADDON_BASE
before r.modis.download was able to start but r.modis.import was not

Modified: grass-addons/grass7/raster/r.modis/r.modis.download/r.modis.download.py
===================================================================
--- grass-addons/grass7/raster/r.modis/r.modis.download/r.modis.download.py	2013-11-13 09:59:08 UTC (rev 58207)
+++ grass-addons/grass7/raster/r.modis/r.modis.download/r.modis.download.py	2013-11-13 16:04:04 UTC (rev 58208)
@@ -81,34 +81,18 @@
 import sys
 from datetime import *
 import grass.script as grass
+from grass.pygrass.functions import get_lib_path
 
-# add the folder containing libraries to python path
-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.getenv('GRASS_ADDON_BASE') and \
-        os.path.isdir(os.path.join(os.getenv('GRASS_ADDON_BASE'), 'r.modis',
-                                   'r.modis')):
-    libmodis = os.path.join(os.getenv('GRASS_ADDON_BASE'), 'r.modis',
-                            '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")
 
-# try to import pymodis (modis) and some class for r.modis.download
-sys.path.append(libmodis)
-try:
-    from rmodislib import product
-    from downmodis import downModis
-except ImportError, e:
-    grass.fatal(e)
+path = get_lib_path(modname='r.modis', libname='libmodis')
+if path is None:
+    grass.fatal("Not able to find the modis library directory.")
+sys.path.append(path)
 
+from rmodislib import product
+from downmodis import downModis
 
+
 def check(home):
     """ Check if a folder it is writable by the user that launch the process
     """

Modified: grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py
===================================================================
--- grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py	2013-11-13 09:59:08 UTC (rev 58207)
+++ grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py	2013-11-13 16:04:04 UTC (rev 58208)
@@ -94,33 +94,19 @@
 import shutil
 import grass.script as grass
 from datetime import date
+from grass.pygrass.functions import get_lib_path
 
-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")
 
-sys.path.append(libmodis)
+path = get_lib_path(modname='r.modis', libname='libmodis')
+if path is None:
+    grass.fatal("Not able to find the modis library directory.")
+sys.path.append(path)
+
+
 # try to import pymodis (modis) and some classes for r.modis.download
-try:
-    from rmodislib import resampling, product, projection
-except ImportError, e:
-    grass.fatal(e)
-try:
-    from convertmodis  import convertModis, createMosaic
-except ImportError, e:
-    grass.fatal(e)
-try:
-    from parsemodis import parseModis
-except ImportError, e:
-    grass.fatal(e)
+from rmodislib import resampling, product, projection
+from convertmodis  import convertModis, createMosaic
+from parsemodis import parseModis
 
 
 def list_files(opt, mosaik=False):



More information about the grass-commit mailing list