Changeset 8012
- Timestamp:
- 07/20/08 16:30:46 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/libgdal.py
r7127 r8012 7 7 try: 8 8 from django.conf import settings 9 lib_ name= settings.GDAL_LIBRARY_PATH9 lib_path = settings.GDAL_LIBRARY_PATH 10 10 except (AttributeError, EnvironmentError, ImportError): 11 lib_ name= None11 lib_path = None 12 12 13 if lib_ name:14 pass13 if lib_path: 14 lib_names = None 15 15 elif os.name == 'nt': 16 16 # Windows NT shared library 17 lib_name = 'gdal15.dll'17 lib_names = ['gdal15'] 18 18 elif 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'] 26 21 else: 27 22 raise OGRException('Unsupported OS "%s"' % os.name) 28 23 24 # Using the ctypes `find_library` utility to find the 25 # path to the GDAL library from the list of library names. 26 if 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 31 if 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 29 36 # This loads the GDAL/OGR C library 30 lgdal = CDLL(lib_ name)37 lgdal = CDLL(lib_path) 31 38 32 39 # On Windows, the GDAL binaries have some OSR routines exported with django/branches/gis/django/contrib/gis/geos/libgeos.py
r7100 r8012 9 9 import atexit, os, re, sys 10 10 from ctypes import c_char_p, Structure, CDLL, CFUNCTYPE, POINTER 11 from ctypes.util import find_library 11 12 from django.contrib.gis.geos.error import GEOSException 12 13 … … 21 22 try: 22 23 from django.conf import settings 23 lib_ name= settings.GEOS_LIBRARY_PATH24 lib_path = settings.GEOS_LIBRARY_PATH 24 25 except (AttributeError, EnvironmentError, ImportError): 25 lib_ name= None26 lib_path = None 26 27 27 # Setting the appropriate name for the GEOS-C library, depending on which 28 # OS and POSIX platform we're running. 29 if lib_name: 30 pass 28 # Setting the appropriate names for the GEOS-C library. 29 if lib_path: 30 lib_names = None 31 31 elif os.name == 'nt': 32 # Windows NT librar y33 lib_name = 'libgeos_c-1.dll'32 # Windows NT libraries 33 lib_names = ['libgeos_c-1'] 34 34 elif os.name == 'posix': 35 platform = os.uname()[0] # Using os.uname() 36 if platform == 'Darwin': 37 # Mac OSX Shared Library (Thanks Matt!) 38 lib_name = 'libgeos_c.dylib' 39 else: 40 # Attempting to use the .so extension for all other platforms 41 lib_name = 'libgeos_c.so' 35 # *NIX libraries 36 lib_names = ['geos_c'] 42 37 else: 43 38 raise GEOSException('Unsupported OS "%s"' % os.name) 39 40 # Using the ctypes `find_library` utility to find the the path to the GEOS 41 # shared library. This is better than manually specifiying each library name 42 # and extension (e.g., libgeos_c.[so|so.1|dylib].). 43 if lib_names: 44 for lib_name in lib_names: 45 lib_path = find_library(lib_name) 46 if not lib_path is None: break 47 48 # No GEOS library could be found. 49 if lib_path is None: 50 raise GEOSException('Could not find the GEOS library (tried "%s"). ' 51 'Try setting GEOS_LIBRARY_PATH in your settings.' % 52 '", "'.join(lib_names)) 44 53 45 54 # Getting the GEOS C library. The C interface (CDLL) is used for … … 47 56 # See the GEOS C API source code for more details on the library function calls: 48 57 # http://geos.refractions.net/ro/doxygen_docs/html/geos__c_8h-source.html 49 lgeos = CDLL(lib_ name)58 lgeos = CDLL(lib_path) 50 59 51 60 # The notice and error handler C function callback definitions. django/branches/gis/django/contrib/gis/utils/geoip.py
r6918 r8012 41 41 import os, re 42 42 from ctypes import c_char_p, c_float, c_int, Structure, CDLL, POINTER 43 from ctypes.util import find_library 43 44 from django.conf import settings 44 45 if not settings._target: settings.configure() … … 48 49 for key in ('GEOIP_PATH', 'GEOIP_LIBRARY_PATH', 'GEOIP_COUNTRY', 'GEOIP_CITY') 49 50 if hasattr(settings, key)) 50 lib_ name= GEOIP_SETTINGS.get('GEOIP_LIBRARY_PATH', None)51 lib_path = GEOIP_SETTINGS.get('GEOIP_LIBRARY_PATH', None) 51 52 52 53 # GeoIP Exception class. … … 55 56 # The shared library for the GeoIP C API. May be downloaded 56 57 # from http://www.maxmind.com/download/geoip/api/c/ 57 if lib_name: 58 pass 59 elif os.name == 'nt': 60 lib_name = 'libGeoIP.dll' 61 elif os.name == 'posix': 62 platform = os.uname()[0] 63 if platform == 'Darwin': 64 lib_name = 'libGeoIP.dylib' 65 else: 66 lib_name = 'libGeoIP.so' 58 if lib_path: 59 lib_name = None 67 60 else: 68 raise GeoIPException('Unknown POSIX platform "%s"' % platform) 69 lgeoip = CDLL(lib_name) 61 # TODO: Is this really the library name for Windows? 62 lib_name = 'GeoIP' 63 64 # Getting the path to the GeoIP library. 65 if lib_name: lib_path = find_library(lib_name) 66 if lib_path is None: raise GeoIPException('Could not find the GeoIP library (tried "%s"). ' 67 'Try setting GEOIP_LIBRARY_PATH in your settings.' % lib_name) 68 lgeoip = CDLL(lib_path) 70 69 71 70 # Regular expressions for recognizing IP addresses and the GeoIP
