소스 검색

pythonlib: fix get_lib_path() for g.extension

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67894 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 9 년 전
부모
커밋
0098d3dc76
1개의 변경된 파일12개의 추가작업 그리고 10개의 파일을 삭제
  1. 12 10
      lib/python/script/utils.py

+ 12 - 10
lib/python/script/utils.py

@@ -268,7 +268,7 @@ def natural_sort(l):
 def get_lib_path(modname, libname=None):
     """Return the path of the libname contained in the module.
     """
-    from os.path import isdir, join
+    from os.path import isdir, join, sep
     from os import getenv
 
     if isdir(join(getenv('GISBASE'), 'etc', modname)):
@@ -282,15 +282,16 @@ def get_lib_path(modname, libname=None):
     elif getenv('GRASS_ADDON_BASE') and \
             isdir(join(getenv('GRASS_ADDON_BASE'), modname, modname)):
         path = join(os.getenv('GRASS_ADDON_BASE'), modname, modname)
-    elif libname and isdir(join('..', libname)): # used by g.extension compilation process
-        path = join('..', libname)
-    elif isdir(join('..', 'etc', modname)):      # used by g.extension compilation process
-        path = join('..', 'etc', modname)
-    elif isdir(join('etc', modname)):            # used by g.extension compilation process
-        path = join('etc', modname)
     else:
-        path = None
-
+        # used by g.extension compilation process
+        cwd = os.getcwd()
+        idx = cwd.find(modname)
+        if idx < 0:
+            return None
+        path = cwd[:idx+len(modname)] + sep + 'etc' + sep + modname
+        if libname:
+            path = join(path, libname)
+    
     return path
 
 
@@ -368,4 +369,5 @@ def set_path(modulename, dirname=None, path='.'):
             pathname = os.path.join(modulename, dirname) if dirname else modulename
             raise ImportError("Not able to find the path '%s' directory "
                               "(current dir '%s')." % (pathname, os.getcwd()))
-        sys.path.append(path)
+        
+        sys.path.insert(0, path)