瀏覽代碼

Add get_lib_path

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57487 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 11 年之前
父節點
當前提交
42c7138187
共有 1 個文件被更改,包括 23 次插入0 次删除
  1. 23 0
      lib/python/pygrass/functions.py

+ 23 - 0
lib/python/pygrass/functions.py

@@ -216,3 +216,26 @@ def r_export(rast, output='', fmt='png', **kargs):
         return output
         return output
     else:
     else:
         raise ValueError('Raster map does not exist.')
         raise ValueError('Raster map does not exist.')
+
+
+def get_lib_path(modname, libname):
+    """Return the path of the libname contained in the module. ::
+
+        >>> get_lib_path(modname='r.modis', libname='libmodis')
+    """
+    from os.path import isdir, join
+    from os import getenv
+
+    if isdir(join(getenv('GISBASE'), 'etc', modname)):
+        path = join(os.getenv('GISBASE'), 'etc', modname)
+    elif getenv('GRASS_ADDON_BASE') and \
+            isdir(join(getenv('GRASS_ADDON_BASE'), 'etc', modname)):
+        path = join(getenv('GRASS_ADDON_BASE'), 'etc', modname)
+    elif getenv('GRASS_ADDON_BASE') and \
+            isdir(join(getenv('GRASS_ADDON_BASE'), modname, modname)):
+        path = join(os.getenv('GRASS_ADDON_BASE'), modname, modname)
+    elif isdir(join('..', libname)):
+        path = join('..', libname)
+    else:
+        path = None
+    return path