Device detection on OS X now directly queries the IOKit registry instead of parsing the output of the ioreg command. This means that the logic for detection on OS X is now very similar to linux.

This commit is contained in:
Kovid Goyal 2009-12-27 12:45:25 -07:00
parent 0b3cf0b19f
commit 0a7dbe6099
3 changed files with 22 additions and 12 deletions

View File

@ -62,7 +62,7 @@ def migrate(old, new):
def debug_device_driver():
from calibre.devices import debug
print debug()
debug(ioreg_to_tmp=True, buf=sys.stdout)
if iswindows:
raw_input('Press Enter to continue...')

View File

@ -27,13 +27,14 @@ def strftime(epoch, zone=time.gmtime):
src[2] = INVERSE_MONTH_MAP[int(src[2])]
return ' '.join(src)
def debug():
def debug(ioreg_to_tmp=False, buf=None):
from calibre.customize.ui import device_plugins
from calibre.devices.scanner import DeviceScanner
from calibre.constants import iswindows, isosx, __version__
from calibre import prints
oldo, olde = sys.stdout, sys.stderr
if buf is None:
buf = StringIO()
sys.stdout = sys.stderr = buf
try:
@ -82,16 +83,17 @@ def debug():
connected_devices = []
for dev in device_plugins():
out('Looking for', dev.__class__.__name__)
connected = s.is_device_connected(dev, debug=True)
connected, det = s.is_device_connected(dev, debug=True)
if connected:
connected_devices.append(dev)
connected_devices.append((dev, det))
errors = {}
success = False
for dev in connected_devices:
for dev, det in connected_devices:
out('Device possibly connected:', dev.__class__.name)
out('Trying to open device...', end=' ')
try:
dev.reset(detected_device=det)
dev.open()
out('OK')
except:
@ -112,10 +114,16 @@ def debug():
out(' ')
if ioreg is not None:
ioreg = 'IOREG Output\n'+ioreg
out(' ')
out('IOREG Output')
if ioreg_to_tmp:
open('/tmp/ioreg.txt', 'wb').write(ioreg)
out('Dont forget to send the contents of /tmp/ioreg.txt')
out('You can open it with the command: open /tmp/ioreg.txt')
else:
out(ioreg)
if hasattr(buf, 'getvalue'):
return buf.getvalue().decode('utf-8')
finally:
sys.stdout = oldo

View File

@ -460,9 +460,9 @@ class Device(DeviceConfig, DevicePlugin):
matches.sort(cmp=dcmp)
drives = {'main':matches[0]}
if len(matches > 1):
if len(matches) > 1:
drives['carda'] = matches[1]
if len(matches > 2):
if len(matches) > 2:
drives['cardb'] = matches[2]
return drives
@ -476,11 +476,13 @@ class Device(DeviceConfig, DevicePlugin):
def open_osx(self):
drives = self.osx_bsd_names()
bsd_drives = dict(**drives)
drives = self.osx_sort_names(drives)
mount_map = usbobserver.get_mounted_filesystems()
for k, v in drives.items():
drives[k] = mount_map.get(k, None)
drives[k] = mount_map.get(v, None)
if drives['main'] is None:
print bsd_drives, mount_map, drives
raise DeviceError(_('Unable to detect the %s mount point. Try rebooting.')%self.__class__.__name__)
self._main_prefix = drives['main']+os.sep
def get_card_prefix(c):