mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2813 (PRS-505 not recognized)
This commit is contained in:
parent
bbc08cc15f
commit
55a4f4a208
@ -4,8 +4,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net> ' \
|
||||
'''
|
||||
Device driver for the SONY PRS-505
|
||||
'''
|
||||
import os
|
||||
import time
|
||||
import os, re, time
|
||||
from itertools import cycle
|
||||
|
||||
from calibre import sanitize_file_name as sanitize
|
||||
@ -30,12 +29,12 @@ class PRS505(CLI, Device):
|
||||
|
||||
VENDOR_NAME = 'SONY'
|
||||
WINDOWS_MAIN_MEM = 'PRS-505'
|
||||
WINDOWS_CARD_A_MEM = ['PRS-505/UC:MS', 'PRS-505/CE:MS']
|
||||
WINDOWS_CARD_B_MEM = ['PRS-505/UC:SD', 'PRS-505/CE:SD']
|
||||
WINDOWS_CARD_A_MEM = re.compile(r'PRS-505/\S+:MS')
|
||||
WINDOWS_CARD_B_MEM = re.compile(r'PRS-505/\S+:SD')
|
||||
|
||||
OSX_MAIN_MEM = ['Sony PRS-505/UC Media', 'Sony PRS-505/CE Media']
|
||||
OSX_CARD_A_MEM = ['Sony PRS-505/UC:MS Media', 'Sony PRS-505/CE:MS Media']
|
||||
OSX_CARD_B_MEM = ['Sony PRS-505/UC:SD', 'Sony PRS-505/CE:SD']
|
||||
OSX_MAIN_MEM = re.compile(r'Sony PRS-505/\S+ Media')
|
||||
OSX_CARD_A_MEM = re.compile(r'Sony PRS-505/\S+:MS Media')
|
||||
OSX_CARD_B_MEM = re.compile(r'Sony PRS-505/\S+:SD')
|
||||
|
||||
MAIN_MEMORY_VOLUME_LABEL = 'Sony Reader Main Memory'
|
||||
STORAGE_CARD_VOLUME_LABEL = 'Sony Reader Storage Card'
|
||||
@ -79,6 +78,7 @@ class PRS505(CLI, Device):
|
||||
self.report_progress(1.0, _('Get device information...'))
|
||||
return (self.__class__.__name__, '', '', '')
|
||||
|
||||
|
||||
def books(self, oncard=None, end_session=True):
|
||||
if oncard == 'carda' and not self._card_a_prefix:
|
||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
||||
|
@ -31,6 +31,8 @@ class Device(DeviceConfig, DevicePlugin):
|
||||
WINDOWS_CARD_A_MEM = None
|
||||
WINDOWS_CARD_B_MEM = None
|
||||
|
||||
# The following are used by the check_ioreg_line method and can be either:
|
||||
# None, a string, a list of strings or a compiled regular expression
|
||||
OSX_MAIN_MEM = None
|
||||
OSX_CARD_A_MEM = None
|
||||
OSX_CARD_B_MEM = None
|
||||
@ -185,6 +187,10 @@ class Device(DeviceConfig, DevicePlugin):
|
||||
if device_id is None or \
|
||||
'VEN_' + str(self.VENDOR_NAME).upper() not in pnp_id:
|
||||
return False
|
||||
|
||||
if hasattr(device_id, 'search'):
|
||||
return device_id.search(pnp_id) is not None
|
||||
|
||||
if isinstance(device_id, basestring):
|
||||
device_id = [device_id]
|
||||
|
||||
@ -269,6 +275,21 @@ class Device(DeviceConfig, DevicePlugin):
|
||||
def osx_sort_names(self, names):
|
||||
return names
|
||||
|
||||
def check_ioreg_line(self, line, pat):
|
||||
if pat is None:
|
||||
return False
|
||||
if not line.strip().endswith('<class IOMedia>'):
|
||||
return False
|
||||
if hasattr(pat, 'search'):
|
||||
return pat.search(line) is not None
|
||||
if isinstance(pat, basestring):
|
||||
pat = [pat]
|
||||
for x in pat:
|
||||
if x in line:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_osx_mountpoints(self, raw=None):
|
||||
raw = self.run_ioreg(raw)
|
||||
lines = raw.splitlines()
|
||||
@ -284,24 +305,12 @@ class Device(DeviceConfig, DevicePlugin):
|
||||
names[loc] = match.group(1)
|
||||
break
|
||||
|
||||
def check_line(line, pat):
|
||||
if pat is None:
|
||||
return False
|
||||
if not line.strip().endswith('<class IOMedia>'):
|
||||
return False
|
||||
if isinstance(pat, basestring):
|
||||
pat = [pat]
|
||||
for x in pat:
|
||||
if x in line:
|
||||
return True
|
||||
return False
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
if check_line(line, self.OSX_MAIN_MEM):
|
||||
if self.check_ioreg_line(line, self.OSX_MAIN_MEM):
|
||||
get_dev_node(lines[i+1:], 'main')
|
||||
if check_line(line, self.OSX_CARD_A_MEM):
|
||||
if self.check_ioreg_line(line, self.OSX_CARD_A_MEM):
|
||||
get_dev_node(lines[i+1:], 'carda')
|
||||
if check_line(line, self.OSX_CARD_B_MEM):
|
||||
if self.check_ioreg_line(line, self.OSX_CARD_B_MEM):
|
||||
get_dev_node(lines[i+1:], 'cardb')
|
||||
if len(names.keys()) == 3:
|
||||
break
|
||||
|
Loading…
x
Reference in New Issue
Block a user