diff options
author | dominique.leuenberger@gmail.com <dominique.leuenberger@gmail.com@c587cffe-e639-0410-9787-d7902ae8ed56> | 2012-04-01 12:42:29 +0000 |
---|---|---|
committer | dominique.leuenberger@gmail.com <dominique.leuenberger@gmail.com@c587cffe-e639-0410-9787-d7902ae8ed56> | 2012-04-01 12:42:29 +0000 |
commit | 74fa49cae01cb5818deaa0c321f7e24d2d5689fd (patch) | |
tree | e7f40ba21f90626ee65de443e255f0ce201b5cbe | |
parent | 9a122991d1331ba213d288b60270bfbb17ddecfc (diff) | |
download | libproxy-git-74fa49cae01cb5818deaa0c321f7e24d2d5689fd.tar.gz |
Speed up importing libproxy in python.
Fixes issue 177.
-rw-r--r-- | bindings/python/libproxy.py | 20 | ||||
-rw-r--r-- | libproxy/cmake/libproxy.cmk | 1 |
2 files changed, 12 insertions, 9 deletions
diff --git a/bindings/python/libproxy.py b/bindings/python/libproxy.py index 15f0210..cb75a4d 100644 --- a/bindings/python/libproxy.py +++ b/bindings/python/libproxy.py @@ -25,21 +25,23 @@ import platform import sys +def _load(name, *versions): + for ver in versions: + try: return ctypes.cdll.LoadLibrary('lib%s.so.%s' % (name, ver)) + except: pass + name_ver = ctypes.util.find_library(name) + if name_ver: + return ctypes.cdll.LoadLibrary(name_ver) + raise ImportError("Unable to find %s library" % name) + # Load C library if platform.system() == "Windows": _libc = ctypes.cdll.msvcrt else: - if not ctypes.util.find_library("c"): - raise ImportError("Unable to import C Library!?!") - _libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library("c")) - + _libc = _load("c", 6) # Load libproxy -if not ctypes.util.find_library("proxy"): - raise ImportError("Unable to import libproxy!?!?") - - -_libproxy = ctypes.cdll.LoadLibrary(ctypes.util.find_library("proxy")) +_libproxy = _load("proxy", 1) _libproxy.px_proxy_factory_get_proxies.restype = ctypes.POINTER(ctypes.c_void_p) class ProxyFactory(object): diff --git a/libproxy/cmake/libproxy.cmk b/libproxy/cmake/libproxy.cmk index 80406af..d0e03e9 100644 --- a/libproxy/cmake/libproxy.cmk +++ b/libproxy/cmake/libproxy.cmk @@ -17,6 +17,7 @@ endif() set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/proxy.cpp PROPERTY COMPILE_DEFINITIONS MODULEDIR="${MODULEDIR}";BUILTIN_MODULES=${BUILTIN_MODULES}) +# When changing the SOVERSION here remember to also bump the 'favorite proxy .so' in python bindings. set_target_properties(libproxy PROPERTIES PREFIX "" VERSION 1.0.0 SOVERSION 1) set_target_properties(libproxy PROPERTIES LINK_INTERFACE_LIBRARIES "") install(TARGETS libproxy DESTINATION ${LIB_INSTALL_DIR}) |