Django

Code

Show
Ignore:
Timestamp:
07/20/08 16:30:46 (6 months ago)
Author:
jbronn
Message:

gis: Now use ctypes.util.find_library to get the C library names. This is preferrable to manually specifying the different library naming schemes used by different platforms/distributions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/gdal/libgdal.py

    r7127 r8012  
    77try: 
    88    from django.conf import settings 
    9     lib_name = settings.GDAL_LIBRARY_PATH 
     9    lib_path = settings.GDAL_LIBRARY_PATH 
    1010except (AttributeError, EnvironmentError, ImportError): 
    11     lib_name = None 
     11    lib_path = None 
    1212 
    13 if lib_name
    14     pass 
     13if lib_path
     14    lib_names = None 
    1515elif os.name == 'nt': 
    1616    # Windows NT shared library 
    17     lib_name = 'gdal15.dll' 
     17    lib_names = ['gdal15'] 
    1818elif os.name == 'posix': 
    19     platform = os.uname()[0] 
    20     if platform == 'Darwin': 
    21         # Mac OSX shared library 
    22         lib_name = 'libgdal.dylib' 
    23     else:  
    24         # Attempting to use .so extension for all other platforms. 
    25         lib_name = 'libgdal.so' 
     19    # *NIX library names. 
     20    lib_names = ['gdal', 'gdal1.5.0'] 
    2621else: 
    2722    raise OGRException('Unsupported OS "%s"' % os.name) 
    2823 
     24# Using the ctypes `find_library` utility  to find the  
     25# path to the GDAL library from the list of library names. 
     26if lib_names: 
     27    for lib_name in lib_names: 
     28        lib_path = find_library(lib_name) 
     29        if not lib_path is None: break 
     30         
     31if lib_path is None: 
     32    raise OGRException('Could not find the GDAL library (tried "%s"). ' 
     33                       'Try setting GDAL_LIBRARY_PATH in your settings.' %  
     34                       '", "'.join(lib_names)) 
     35 
    2936# This loads the GDAL/OGR C library 
    30 lgdal = CDLL(lib_name
     37lgdal = CDLL(lib_path
    3138 
    3239# On Windows, the GDAL binaries have some OSR routines exported with