Browse Source

pygrass: change dirname in set_path() to optional - this functions needs major revision

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67535 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 9 years ago
parent
commit
fecac8a6c1
1 changed files with 12 additions and 7 deletions
  1. 12 7
      lib/python/pygrass/utils.py

+ 12 - 7
lib/python/pygrass/utils.py

@@ -283,7 +283,7 @@ def r_export(rast, output='', fmt='png', **kargs):
         raise ValueError('Raster map does not exist.')
 
 
-def get_lib_path(modname, libname):
+def get_lib_path(modname, libname=None):
     """Return the path of the libname contained in the module.
     """
     from os.path import isdir, join
@@ -291,7 +291,7 @@ def get_lib_path(modname, libname):
 
     if isdir(join(getenv('GISBASE'), 'etc', modname)):
         path = join(os.getenv('GISBASE'), 'etc', modname)
-    elif getenv('GRASS_ADDON_BASE') and \
+    elif getenv('GRASS_ADDON_BASE') and libname and \
             isdir(join(getenv('GRASS_ADDON_BASE'), 'etc', modname, libname)):
         path = join(getenv('GRASS_ADDON_BASE'), 'etc', modname, libname)
     elif getenv('GRASS_ADDON_BASE') and \
@@ -300,18 +300,23 @@ def get_lib_path(modname, libname):
     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)):
+    elif libname and isdir(join('..', libname)):
         path = join('..', libname)
     else:
         path = None
     return path
 
 
-def set_path(modulename, dirname, path='.'):
-    import sys
+def set_path(modulename, dirname=None, path='.'):
     """Set sys.path looking in the the local directory GRASS directories."""
-    pathlib = os.path.join(path, dirname)
-    if os.path.exists(pathlib):
+    import sys
+    # TODO: why dirname is checked first - the logic should be revised
+    # TODO  probably also 'path' should be also removed - it's used only by
+    #       compilation process for addons (see r.green for details)
+    pathlib = None
+    if dirname:
+        pathlib = os.path.join(path, dirname)
+    if pathlib and os.path.exists(pathlib):
         # we are running the script from the script directory
         sys.path.append(os.path.abspath(pathlib))
     else: