Changeset 8012 for django/branches/gis/django/contrib/gis/geos
- Timestamp:
- 07/20/08 16:30:46 (6 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
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.
