mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Experimental windows support for cybook driver (testing needed)
This commit is contained in:
commit
1ef8964487
@ -42,6 +42,8 @@ class BookList(_BookList):
|
|||||||
# Filter out anything that isn't in the list of supported ebook types
|
# Filter out anything that isn't in the list of supported ebook types
|
||||||
for book_type in EBOOK_TYPES:
|
for book_type in EBOOK_TYPES:
|
||||||
for filename in fnmatch.filter(files, '*.%s' % (book_type)):
|
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
|
# 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
|
# title_-_author_number.extention We want to see if the file name is
|
||||||
# in this format.
|
# in this format.
|
||||||
@ -55,9 +57,8 @@ class BookList(_BookList):
|
|||||||
# the filename without the extension
|
# the filename without the extension
|
||||||
else:
|
else:
|
||||||
book_title = os.path.splitext(filename)[0].replace('_', ' ')
|
book_title = os.path.splitext(filename)[0].replace('_', ' ')
|
||||||
|
|
||||||
book_path = os.path.join(path, filename)
|
self.append(Book(os.path.join(path, filename), book_title, book_author))
|
||||||
self.append(Book(book_path, book_title, book_author))
|
|
||||||
|
|
||||||
def add_book(self, path, title):
|
def add_book(self, path, title):
|
||||||
self.append(Book(path, title, ""))
|
self.append(Book(path, title, ""))
|
||||||
|
@ -220,10 +220,44 @@ class CYBOOKG3(Device):
|
|||||||
path = path.replace('card:', self._card_prefix[:-1])
|
path = path.replace('card:', self._card_prefix[:-1])
|
||||||
return path
|
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):
|
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):
|
def open_osx(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def open_linux(self):
|
def open_linux(self):
|
||||||
import dbus
|
import dbus
|
||||||
bus = dbus.SystemBus()
|
bus = dbus.SystemBus()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user