mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-01-20 07:54:33 +01:00
Fix libimobiledevice failing to load library on unsupported linux builds
Also some pep8 cleanup
This commit is contained in:
parent
b4c908104f
commit
ceed1a1667
1 changed files with 28 additions and 19 deletions
|
|
@ -20,12 +20,13 @@
|
|||
c_char, c_char_p, c_int, c_long, c_ubyte, c_uint, c_ulonglong, c_void_p,
|
||||
POINTER, string_at, Structure)
|
||||
|
||||
from calibre.constants import DEBUG, islinux, isosx, iswindows
|
||||
from calibre.constants import DEBUG, isosx, iswindows
|
||||
from calibre.devices.idevice.parse_xml import XmlPropertyListParser
|
||||
from calibre.devices.usbms.driver import debug_print
|
||||
|
||||
|
||||
class libiMobileDeviceException(Exception):
|
||||
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
|
|
@ -34,6 +35,7 @@ def __str__(self):
|
|||
|
||||
|
||||
class libiMobileDeviceIOException(Exception):
|
||||
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
|
|
@ -42,6 +44,7 @@ def __str__(self):
|
|||
|
||||
|
||||
class AFC_CLIENT_T(Structure):
|
||||
|
||||
'''
|
||||
http://www.libimobiledevice.org/docs/html/structafc__client__private.html
|
||||
'''
|
||||
|
|
@ -74,6 +77,7 @@ class AFC_CLIENT_T(Structure):
|
|||
|
||||
|
||||
class HOUSE_ARREST_CLIENT_T(Structure):
|
||||
|
||||
'''
|
||||
http://www.libimobiledevice.org/docs/html/structhouse__arrest__client__private.html
|
||||
'''
|
||||
|
|
@ -94,6 +98,7 @@ class HOUSE_ARREST_CLIENT_T(Structure):
|
|||
|
||||
|
||||
class IDEVICE_T(Structure):
|
||||
|
||||
'''
|
||||
http://www.libimobiledevice.org/docs/html/structidevice__private.html
|
||||
'''
|
||||
|
|
@ -104,6 +109,7 @@ class IDEVICE_T(Structure):
|
|||
|
||||
|
||||
class INSTPROXY_CLIENT_T(Structure):
|
||||
|
||||
'''
|
||||
http://www.libimobiledevice.org/docs/html/structinstproxy__client__private.html
|
||||
'''
|
||||
|
|
@ -129,6 +135,7 @@ class INSTPROXY_CLIENT_T(Structure):
|
|||
|
||||
|
||||
class LOCKDOWND_CLIENT_T(Structure):
|
||||
|
||||
'''
|
||||
http://www.libimobiledevice.org/docs/html/structlockdownd__client__private.html
|
||||
'''
|
||||
|
|
@ -152,6 +159,7 @@ class LOCKDOWND_CLIENT_T(Structure):
|
|||
|
||||
|
||||
class LOCKDOWND_SERVICE_DESCRIPTOR(Structure):
|
||||
|
||||
'''
|
||||
from libimobiledevice/include/libimobiledevice/lockdown.h
|
||||
'''
|
||||
|
|
@ -162,6 +170,7 @@ class LOCKDOWND_SERVICE_DESCRIPTOR(Structure):
|
|||
|
||||
|
||||
class libiMobileDevice():
|
||||
|
||||
'''
|
||||
Wrapper for libiMobileDevice
|
||||
'''
|
||||
|
|
@ -323,7 +332,7 @@ def disconnect_idevice(self):
|
|||
if self.device_mounted:
|
||||
self._afc_client_free()
|
||||
self._house_arrest_client_free()
|
||||
#self._lockdown_goodbye()
|
||||
# self._lockdown_goodbye()
|
||||
self._idevice_free()
|
||||
self.device_mounted = False
|
||||
else:
|
||||
|
|
@ -332,7 +341,7 @@ def disconnect_idevice(self):
|
|||
def dismount_ios_media_folder(self):
|
||||
if self.device_mounted:
|
||||
self._afc_client_free()
|
||||
#self._lockdown_goodbye()
|
||||
# self._lockdown_goodbye()
|
||||
self._idevice_free()
|
||||
self.device_mounted = False
|
||||
|
||||
|
|
@ -438,10 +447,10 @@ def listdir(self, path, get_stats=True):
|
|||
return self._afc_read_directory(path, get_stats=get_stats)
|
||||
|
||||
def load_library(self):
|
||||
if islinux:
|
||||
env = "linux"
|
||||
self.lib = cdll.LoadLibrary('libimobiledevice.so.5')
|
||||
self.plist_lib = cdll.LoadLibrary('libplist.so.3')
|
||||
if iswindows:
|
||||
env = "Windows"
|
||||
self.lib = cdll.LoadLibrary('libimobiledevice.dll')
|
||||
self.plist_lib = cdll.LoadLibrary('libplist.dll')
|
||||
elif isosx:
|
||||
env = "OS X"
|
||||
|
||||
|
|
@ -458,11 +467,13 @@ def load_library(self):
|
|||
self.plist_lib = cdll.LoadLibrary(os.path.join(getattr(sys, 'frameworks_dir'), path))
|
||||
else:
|
||||
self.plist_lib = cdll.LoadLibrary(path)
|
||||
elif iswindows:
|
||||
env = "Windows"
|
||||
self.lib = cdll.LoadLibrary('libimobiledevice.dll')
|
||||
self.plist_lib = cdll.LoadLibrary('libplist.dll')
|
||||
|
||||
else:
|
||||
env = "linux"
|
||||
try:
|
||||
self.lib = cdll.LoadLibrary('libimobiledevice.so.5')
|
||||
except EnvironmentError:
|
||||
self.lib = cdll.LoadLibrary('libimobiledevice.so')
|
||||
self.plist_lib = cdll.LoadLibrary('libplist.so.3')
|
||||
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))
|
||||
|
|
@ -506,7 +517,7 @@ def mount_ios_app(self, app_name=None, app_id=None):
|
|||
self._instproxy_client_options_free()
|
||||
self._instproxy_client_free()
|
||||
|
||||
if not app_name in self.installed_apps:
|
||||
if app_name not in self.installed_apps:
|
||||
self._log(" {0} not installed on this iDevice".format(repr(app_name)))
|
||||
self.disconnect_idevice()
|
||||
else:
|
||||
|
|
@ -1388,7 +1399,7 @@ def _idevice_get_device_list(self):
|
|||
device_list.append(devices[index].contents.value)
|
||||
index += 1
|
||||
self._log(" {0}".format(repr(device_list)))
|
||||
#self.lib.idevice_device_list_free()
|
||||
# self.lib.idevice_device_list_free()
|
||||
return device_list
|
||||
|
||||
def _idevice_new(self):
|
||||
|
|
@ -1458,8 +1469,8 @@ def _instproxy_browse(self, applist=[]):
|
|||
raise libiMobileDeviceException(error_description)
|
||||
else:
|
||||
# Get the number of apps
|
||||
#app_count = self.lib.plist_array_get_size(apps)
|
||||
#self._log(" app_count: {0}".format(app_count))
|
||||
# app_count = self.lib.plist_array_get_size(apps)
|
||||
# self._log(" app_count: {0}".format(app_count))
|
||||
|
||||
# Convert the app plist to xml
|
||||
xml = POINTER(c_void_p)()
|
||||
|
|
@ -1628,7 +1639,7 @@ def _lockdown_client_new_with_handshake(self):
|
|||
self._log_location()
|
||||
|
||||
lockdownd_client_t = POINTER(LOCKDOWND_CLIENT_T)()
|
||||
#SERVICE_NAME = create_string_buffer('calibre')
|
||||
# SERVICE_NAME = create_string_buffer('calibre')
|
||||
SERVICE_NAME = c_void_p()
|
||||
error = self.lib.lockdownd_client_new_with_handshake(byref(self.device),
|
||||
byref(lockdownd_client_t),
|
||||
|
|
@ -1719,7 +1730,6 @@ def _lockdown_get_device_name(self):
|
|||
return device_name
|
||||
|
||||
def _lockdown_get_value(self, requested_items=[]):
|
||||
|
||||
'''
|
||||
Retrieves a preferences plist using an optional domain and/or key name.
|
||||
|
||||
|
|
@ -1937,4 +1947,3 @@ def _log_location(self, *args):
|
|||
|
||||
def __null(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue