Skip to content

Commit

Permalink
Workaround for Jython 2.7a2; it has no ctypes.util
Browse files Browse the repository at this point in the history
Related issue: #9
See also: http://bugs.jython.org/issue1916
  • Loading branch information
dahlia committed Jun 11, 2012
1 parent 6c36156 commit f50d219
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions wand/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"""
import ctypes
import ctypes.util
try:
import ctypes.util
except ImportError:
pass
import os
import os.path
import platform
Expand All @@ -23,7 +26,6 @@ def load_library():
"""
libpath = None
system = platform.system()

magick_home = os.environ.get('MAGICK_HOME')
if magick_home:
if system == 'Windows':
Expand All @@ -33,25 +35,29 @@ def load_library():
else:
libpath = 'lib', 'libMagickWand.so',
libpath = os.path.join(magick_home, *libpath)
else:
elif hasattr(ctypes, 'util'):
if system == 'Windows':
libpath = ctypes.util.find_library('CORE_RL_wand_')
else:
libpath = ctypes.util.find_library('MagickWand')
else:
raise ImportError('cannot find MagickWand library; explicitly set '
'MAGICK_HOME environment variable')
libwand = ctypes.CDLL(libpath)

if system == 'Windows':
# On Windows, the API is split between two libs. On other platforms,
# it's all contained in one.
libmagick_filename = 'CORE_RL_magick_'
if magick_home:
libmagick_path = os.path.join(magick_home,
libmagick_filename + '.dll')
else:
elif hasattr(ctypes, 'util'):
libmagick_path = ctypes.util.find_library(libmagick_filename)
else:
raise ImportError('cannot find MagickWand library; explicitly set '
'MAGICK_HOME environment variable')
libmagick = ctypes.CDLL(libmagick_path)
return libwand, libmagick

return libwand, libwand


Expand Down

0 comments on commit f50d219

Please sign in to comment.