diff --git a/src/calibre/devices/idevice/libimobiledevice.py b/src/calibre/devices/idevice/libimobiledevice.py index 2051ed4219..0cdf010316 100644 --- a/src/calibre/devices/idevice/libimobiledevice.py +++ b/src/calibre/devices/idevice/libimobiledevice.py @@ -25,6 +25,29 @@ from calibre.devices.idevice.parse_xml import XmlPropertyListParser from calibre.devices.usbms.driver import debug_print +def load_library(): + if iswindows: + env = "Windows" + lib = cdll.LoadLibrary('libimobiledevice.dll') + plist_lib = cdll.LoadLibrary('libplist.dll') + elif isosx: + env = "OS X" + # Load libiMobileDevice + path = 'libimobiledevice.6.dylib' + lib = cdll.LoadLibrary(os.path.join(getattr(sys, 'frameworks_dir'), path)) + # Load libplist + path = 'libplist.3.dylib' + plist_lib = cdll.LoadLibrary(os.path.join(getattr(sys, 'frameworks_dir'), path)) + else: + env = "linux" + try: + lib = cdll.LoadLibrary('libimobiledevice.so.6') + except EnvironmentError: + lib = cdll.LoadLibrary('libimobiledevice.so') + plist_lib = cdll.LoadLibrary('libplist.so.3') + return env, lib, plist_lib + + class libiMobileDeviceException(Exception): def __init__(self, value): @@ -447,33 +470,7 @@ class libiMobileDevice(): return self._afc_read_directory(path, get_stats=get_stats) def load_library(self): - if iswindows: - env = "Windows" - self.lib = cdll.LoadLibrary('libimobiledevice.dll') - self.plist_lib = cdll.LoadLibrary('libplist.dll') - elif isosx: - env = "OS X" - - # Load libiMobileDevice - path = 'libimobiledevice.6.dylib' - if hasattr(sys, 'frameworks_dir'): - self.lib = cdll.LoadLibrary(os.path.join(getattr(sys, 'frameworks_dir'), path)) - else: - self.lib = cdll.LoadLibrary(path) - - # Load libplist - path = 'libplist.3.dylib' - if hasattr(sys, 'frameworks_dir'): - self.plist_lib = cdll.LoadLibrary(os.path.join(getattr(sys, 'frameworks_dir'), path)) - else: - self.plist_lib = cdll.LoadLibrary(path) - else: - env = "linux" - try: - self.lib = cdll.LoadLibrary('libimobiledevice.so.6') - except EnvironmentError: - self.lib = cdll.LoadLibrary('libimobiledevice.so') - self.plist_lib = cdll.LoadLibrary('libplist.so.3') + env, self.lib, self.plist_lib = load_library() self._log_location(env) self._log(" libimobiledevice loaded from '{0}'".format(self.lib._name)) self._log(" libplist loaded from '{0}'".format(self.plist_lib._name)) diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index 4cd743ecc2..3110d1348f 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -45,6 +45,10 @@ class BuildTest(unittest.TestCase): self.assertEqual(regex.findall(r'(?i)(a)(b)', 'ab cd AB 1a1b'), [('a', 'b'), ('A', 'B')]) self.assertEqual(regex.escape('a b', literal_spaces=True), 'a b') + def test_imobiledevice(self): + from calibre.devices.idevice.libimobiledevice import load_library + load_library() + def test_chardet(self): from chardet import detect raw = 'mūsi Füße'.encode('utf-8')