Experimental windows support for cybook driver (testing needed)

This commit is contained in:
Kovid Goyal 2009-01-03 17:31:45 -08:00
commit 1ef8964487
2 changed files with 39 additions and 4 deletions

View File

@ -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, ""))

View File

@ -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()