try every dll that matches by name in PATH
This commit is contained in:
parent
5179e018e2
commit
bd22e3ef75
1 changed files with 26 additions and 5 deletions
|
@ -23,9 +23,28 @@
|
||||||
from __future__ import absolute_import, division, print_function, \
|
from __future__ import absolute_import, division, print_function, \
|
||||||
with_statement
|
with_statement
|
||||||
|
|
||||||
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
def find_library_nt(name):
|
||||||
|
# modified from ctypes.util
|
||||||
|
# ctypes.util.find_library just returns first result he found
|
||||||
|
# but we want to try them all
|
||||||
|
# because on Windows, users may have both 32bit and 64bit version installed
|
||||||
|
results = []
|
||||||
|
for directory in os.environ['PATH'].split(os.pathsep):
|
||||||
|
fname = os.path.join(directory, name)
|
||||||
|
if os.path.isfile(fname):
|
||||||
|
results.append(fname)
|
||||||
|
if fname.lower().endswith(".dll"):
|
||||||
|
continue
|
||||||
|
fname = fname + ".dll"
|
||||||
|
if os.path.isfile(fname):
|
||||||
|
results.append(fname)
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
def find_library(possible_lib_names, search_symbol, library_name):
|
def find_library(possible_lib_names, search_symbol, library_name):
|
||||||
import ctypes.util
|
import ctypes.util
|
||||||
from ctypes import CDLL
|
from ctypes import CDLL
|
||||||
|
@ -41,6 +60,9 @@ def find_library(possible_lib_names, search_symbol, library_name):
|
||||||
lib_names.append('lib' + lib_name)
|
lib_names.append('lib' + lib_name)
|
||||||
|
|
||||||
for name in lib_names:
|
for name in lib_names:
|
||||||
|
if os.name == "nt":
|
||||||
|
paths.extend(find_library_nt(name))
|
||||||
|
else:
|
||||||
path = ctypes.util.find_library(name)
|
path = ctypes.util.find_library(name)
|
||||||
if path:
|
if path:
|
||||||
paths.append(path)
|
paths.append(path)
|
||||||
|
@ -56,8 +78,7 @@ def find_library(possible_lib_names, search_symbol, library_name):
|
||||||
'/usr/local/lib*/lib%s.*' % name,
|
'/usr/local/lib*/lib%s.*' % name,
|
||||||
'/usr/lib*/lib%s.*' % name,
|
'/usr/lib*/lib%s.*' % name,
|
||||||
'lib%s.*' % name,
|
'lib%s.*' % name,
|
||||||
'%s.dll' % name,
|
'%s.dll' % name]
|
||||||
'lib%s.dll' % name]
|
|
||||||
|
|
||||||
for pat in patterns:
|
for pat in patterns:
|
||||||
files = glob.glob(pat)
|
files = glob.glob(pat)
|
||||||
|
|
Loading…
Add table
Reference in a new issue