From 1d4c9a6022d52c3db74f6bae29f3fa3639faf25d Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 3 Jan 2009 17:43:10 -0500 Subject: [PATCH 1/2] Windows support for Cybook driver --- src/calibre/devices/cybookg3/driver.py | 36 +++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index 5c4c1cfe24..661c98cc44 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -220,10 +220,44 @@ class CYBOOKG3(Device): path = path.replace('card:', self._card_prefix[:-1]) return path + + def _windows_match_device(self, device_id): + device_id = device_id.upper() + vid, pid = hex(cls.VENDOR_ID)[2:], hex(cls.PRODUCT_ID)[2:] + while len(vid) < 4: vid = '0' + vid + while len(pid) < 4: pid = '0' + pid + if 'VID_'+vid in device_id and 'PID_'+pid in device_id: + return True + return False + + # This only supports Windows >= 2000 def open_windows(self): - raise NotImplementedError() + drives = [] + wmi = __import__('wmi', globals(), locals(), [], -1) + c = wmi.WMI() + for drive in c.Win32_DiskDrive(): + if self._windows_match_device(str(drive.PNPDeviceID)): + if drive.Partitions == 0: + continue + try: + partition = drive.associators("Win32_DiskDriveToDiskPartition")[0] + logical_disk = partition.associators('Win32_LogicalDiskToPartition')[0] + prefix = logical_disk.DeviceID+os.sep + drives.append((drive.Index, prefix)) + except IndexError: + continue + + if not drives: + raise DeviceError(_('Unable to detect the %s disk drive. Try rebooting.')%self.__class__.__name__) + + 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() + def open_linux(self): import dbus bus = dbus.SystemBus() From 394b93cb43943cbd65c8f3013cfdd087404807b4 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 3 Jan 2009 18:04:19 -0500 Subject: [PATCH 2/2] Cybook driver: Set author correctly when no author is given --- src/calibre/devices/cybookg3/books.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/cybookg3/books.py b/src/calibre/devices/cybookg3/books.py index 9a1689af0b..ed3df812db 100644 --- a/src/calibre/devices/cybookg3/books.py +++ b/src/calibre/devices/cybookg3/books.py @@ -42,6 +42,8 @@ class BookList(_BookList): # Filter out anything that isn't in the list of supported ebook types for book_type in EBOOK_TYPES: for filename in fnmatch.filter(files, '*.%s' % (book_type)): + book_title = '' + book_author = '' # Calibre uses a specific format for file names. They take the form # title_-_author_number.extention We want to see if the file name is # in this format. @@ -55,9 +57,8 @@ class BookList(_BookList): # the filename without the extension else: book_title = os.path.splitext(filename)[0].replace('_', ' ') - - book_path = os.path.join(path, filename) - self.append(Book(book_path, book_title, book_author)) + + self.append(Book(os.path.join(path, filename), book_title, book_author)) def add_book(self, path, title): self.append(Book(path, title, ""))