18 """libdiscid dynamic loading code and constants
20 The code that works with Disc objects is in disc.py
26 from ctypes
import c_void_p, c_char_p
27 from ctypes.util
import find_library
31 _LIB_BASE_NAME =
"discid"
32 _LIB_MAJOR_VERSION = 0
36 """Find a library by base-name and major version
38 windows_names = [
"%s.dll" % name,
"lib%s.dll" % name,
39 "lib%s-%d.dll" % (name, version)]
45 if sys.platform
in [
"darwin",
"cygwin"]:
48 elif sys.platform ==
"win32":
49 for lib_name
in windows_names:
50 if os.path.isfile(lib_name):
56 lib_name =
"./lib%s.so.%d" % (name, version)
57 if os.path.isfile(lib_name):
65 lib_file = find_library(name)
70 if lib_file
is None and sys.platform ==
"win32":
71 for lib_name
in windows_names:
73 lib_file = find_library(lib_name)
78 if sys.platform ==
"win32":
79 lib_file =
"%s.dll" % name
80 elif sys.platform ==
"darwin":
81 lib_file =
"lib%s.%d.dylib" % (name, version)
82 elif sys.platform ==
"cygwin":
83 lib_file =
"cyg%s-%d.dll" % (name, version)
85 lib_file =
"lib%s.so.%d" % (name, version)
90 """Open a library by name or location
93 return ctypes.cdll.LoadLibrary(lib_name)
94 except OSError
as exc:
95 if lib_name
not in str(exc):
97 raise OSError(
"could not find libdiscid: %s" % lib_name)
107 _LIB.discid_get_version_string.argtypes = ()
108 _LIB.discid_get_version_string.restype = c_char_p
109 except AttributeError:
112 """Get the version string of libdiscid
115 version_string = _LIB.discid_get_version_string()
116 except AttributeError:
117 return "libdiscid < 0.4.0"
121 _LIB.discid_get_default_device.argtypes = ()
122 _LIB.discid_get_default_device.restype = c_char_p
124 """The default device to use for :func:`read` on this platform
125 given as a :obj:`unicode` or :obj:`str <python:str>` object.
127 device = _LIB.discid_get_default_device()
131 _LIB.discid_get_feature_list.argtypes = (c_void_p, )
132 _LIB.discid_get_feature_list.restype =
None
133 except AttributeError:
134 _features_available =
False
136 _features_available =
True
138 """Get the supported features for the platform.
141 if _features_available:
142 c_features = (c_char_p * 32)()
143 _LIB.discid_get_feature_list(c_features)
144 for feature
in c_features:
146 features.append(
_decode(feature))
153 except AttributeError:
157 if (sys.platform.startswith(
"linux")
and
158 not os.path.isfile(
"/usr/lib/libdiscid.so.0.3.0")
159 and not os.path.isfile(
"/usr/lib64/libdiscid.so.0.3.0")):
160 features += [
"mcn",
"isrc"]
161 elif sys.platform
in [
"darwin",
"win32"]:
162 features += [
"mcn",
"isrc"]