Django

Code

Show
Ignore:
Timestamp:
07/20/08 16:30:46 (4 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/utils/geoip.py

    r6918 r8012  
    4141import os, re 
    4242from ctypes import c_char_p, c_float, c_int, Structure, CDLL, POINTER 
     43from ctypes.util import find_library 
    4344from django.conf import settings 
    4445if not settings._target: settings.configure() 
     
    4849                      for key in ('GEOIP_PATH', 'GEOIP_LIBRARY_PATH', 'GEOIP_COUNTRY', 'GEOIP_CITY') 
    4950                      if hasattr(settings, key)) 
    50 lib_name = GEOIP_SETTINGS.get('GEOIP_LIBRARY_PATH', None) 
     51lib_path = GEOIP_SETTINGS.get('GEOIP_LIBRARY_PATH', None) 
    5152 
    5253# GeoIP Exception class. 
     
    5556# The shared library for the GeoIP C API.  May be downloaded 
    5657#  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' 
     58if lib_path: 
     59    lib_name = None 
    6760else: 
    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. 
     65if lib_name: lib_path = find_library(lib_name) 
     66if 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) 
     68lgeoip = CDLL(lib_path) 
    7069 
    7170# Regular expressions for recognizing IP addresses and the GeoIP