From 426cde07dd975454502f1317a04acfea75f80906 Mon Sep 17 00:00:00 2001 From: John Schember Date: Wed, 7 Jan 2009 19:46:36 -0500 Subject: [PATCH 1/2] Merge CLI class into Driver --- src/calibre/devices/cybookg3/driver.py | 3 +-- src/calibre/devices/kindle/driver.py | 3 +-- src/calibre/devices/usbms/cli.py | 16 ---------------- src/calibre/devices/usbms/driver.py | 2 ++ 4 files changed, 4 insertions(+), 20 deletions(-) delete mode 100644 src/calibre/devices/usbms/cli.py diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index d367a23fc4..e3c0c1747a 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -7,9 +7,8 @@ Device driver for Bookeen's Cybook Gen 3 import os, fnmatch from calibre.devices.usbms.driver import USBMS -from calibre.devices.usbms.cli import CLI -class CYBOOKG3(USBMS, CLI): +class CYBOOKG3(USBMS): MIME_MAP = { 'mobi' : 'application/mobi', 'prc' : 'application/prc', diff --git a/src/calibre/devices/kindle/driver.py b/src/calibre/devices/kindle/driver.py index 29152c4186..06c3b1cf27 100755 --- a/src/calibre/devices/kindle/driver.py +++ b/src/calibre/devices/kindle/driver.py @@ -7,9 +7,8 @@ Device driver for Amazon's Kindle import os, fnmatch from calibre.devices.usbms.driver import USBMS -from calibre.devices.usbms.cli import CLI -class KINDLE(USBMS, CLI): +class KINDLE(USBMS): MIME_MAP = { 'azw' : 'application/azw', 'mobi' : 'application/mobi', diff --git a/src/calibre/devices/usbms/cli.py b/src/calibre/devices/usbms/cli.py deleted file mode 100644 index 35a3a84824..0000000000 --- a/src/calibre/devices/usbms/cli.py +++ /dev/null @@ -1,16 +0,0 @@ -__license__ = 'GPL v3' -__copyright__ = '2009, John Schember Date: Wed, 7 Jan 2009 20:40:09 -0500 Subject: [PATCH 2/2] OS X support --- src/calibre/devices/cybookg3/driver.py | 3 ++ src/calibre/devices/usbms/device.py | 60 ++++++++++++++++++++++++-- src/calibre/devices/usbms/driver.py | 1 + 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index e3c0c1747a..ed0891f256 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -27,6 +27,9 @@ class CYBOOKG3(USBMS): VENDOR_NAME = 'BOOKEEN' PRODUCT_NAME = 'CYBOOK_GEN3' + OSX_NAME_MAIN_MEM = 'Bookeen Cybook Gen3 -FD Media' + OSX_NAME_CARD_MEM = 'Bookeen Cybook Gen3 -SD Media' + MAIN_MEMORY_VOLUME_LABEL = 'Cybook Gen 3 Main Memory' STORAGE_CARD_VOLUME_LABEL = 'Cybook Gen 3 Storage Card' diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 3a2b8af298..24ad957b12 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -18,6 +18,19 @@ class Device(_Device): as USB Mass Storage devices. If you are writing such a driver, inherit from this class. ''' + + VENDOR_ID = 0x0 + PRODUCT_ID = 0x0 + BCD = 0x0 + + VENDOR_NAME = '' + PRODUCT_NAME = '' + + OSX_NAME_MAIN_MEM = '' + OSX_NAME_CARD_MEM = '' + + MAIN_MEMORY_VOLUME_LABEL = '' + STORAGE_CARD_VOLUME_LABEL = '' FDI_TEMPLATE = \ ''' @@ -156,11 +169,50 @@ class Device(_Device): drives.sort(cmp=lambda a, b: cmp(a[0], b[0])) self._main_prefix = drives[0][1] if len(drives) > 1: - self._card_prefix = drives[1][1] - - def open_osx(self): - raise NotImplementedError() + self._card_prefix = drives[1][1] + @classmethod + def get_osx_mountpoints(cls, raw=None): + if raw is None: + ioreg = '/usr/sbin/ioreg' + if not os.access(ioreg, os.X_OK): + ioreg = 'ioreg' + raw = subprocess.Popen((ioreg+' -w 0 -S -c IOMedia').split(), stdout=subprocess.PIPE).stdout.read() + lines = raw.splitlines() + names = {} + + def get_dev_node(lines, loc): + for line in lines: + line = line.strip() + if line.endswith('}'): + break + match = re.search(r'"BSD Name"\s+=\s+"(.*?)"', line) + if match is not None: + names[loc] = match.group(1) + break + + for i, line in enumerate(lines): + if line.strip().endswith('') and OSX_NAME_MAIN_MEM in line: + get_dev_node(lines[i+1:], 'main') + if line.strip().endswith('') and OSX_NAME_CARD_MEM in line: + get_dev_node(lines[i+1:], 'card') + if len(names.keys()) == 2: + break + return names + + def open_osx(self): + mount = subprocess.Popen('mount', shell=True, stdout=subprocess.PIPE).stdout.read() + names = self.get_osx_mountpoints() + dev_pat = r'/dev/%s(\w*)\s+on\s+([^\(]+)\s+' + if 'main' not in names.keys(): + raise DeviceError(_('Unable to detect the %s disk drive. Try rebooting.')%self.__class__.__name__) + main_pat = dev_pat%names['main'] + self._main_prefix = re.search(main_pat, mount).group(2) + os.sep + card_pat = names['card'] if 'card' in names.keys() else None + if card_pat is not None: + card_pat = dev_pat%card_pat + self._card_prefix = re.search(card_pat, mount).group(2) + os.sep + def open_linux(self): import dbus bus = dbus.SystemBus() diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index 4e6d423927..733ce76ae7 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -16,6 +16,7 @@ from calibre.devices.errors import FreeSpaceError class USBMS(Device): EBOOK_DIR = '' MIME_MAP = {} + FORMATS = [] def __init__(self, key='-1', log_packets=False, report_progress=None): pass