Get the device path for matched books - the kobo stores kepubs in its own directory structure. This lays the groundwork for adding annotations support to the Kobo driver

This commit is contained in:
Timothy Legge 2011-10-16 22:59:55 -03:00
parent 8e7a444ae3
commit 05275a3098
4 changed files with 23 additions and 4 deletions

View File

@ -77,6 +77,11 @@ class KOBO(USBMS):
self.book_class = Book
self.dbversion = 7
def create_annotations_path(self, mdata, device_path=None):
if device_path:
return device_path
return USBMS.create_annotations_path(self, mdata)
def books(self, oncard=None, end_session=True):
from calibre.ebooks.metadata.meta import path_to_ext

View File

@ -1147,3 +1147,6 @@ class Device(DeviceConfig, DevicePlugin):
os.makedirs(filedir)
return filepath
def create_annotations_path(self, mdata, device_path=None):
return self.create_upload_path(os.path.abspath('/<storage>'), mdata, 'x.bookmark', create_dirs=False)

View File

@ -41,13 +41,21 @@ class FetchAnnotationsAction(InterfaceAction):
fmts.append(format.lower())
return fmts
def get_device_path_from_id(id_):
paths = []
for x in ('memory', 'card_a', 'card_b'):
x = getattr(self.gui, x+'_view').model()
paths += x.paths_for_db_ids(set([id_]), as_map=True)[id_]
return paths[0].path if paths else None
def generate_annotation_paths(ids, db, device):
# Generate path templates
# Individual storage mount points scanned/resolved in driver.get_annotations()
path_map = {}
for id in ids:
path = get_device_path_from_id(id)
mi = db.get_metadata(id, index_is_id=True)
a_path = device.create_upload_path(os.path.abspath('/<storage>'), mi, 'x.bookmark', create_dirs=False)
a_path = device.create_annotations_path(mi, path)
path_map[id] = dict(path=a_path, fmts=get_formats(id))
return path_map

View File

@ -1239,11 +1239,14 @@ class DeviceBooksModel(BooksModel): # {{{
def paths(self, rows):
return [self.db[self.map[r.row()]].path for r in rows ]
def paths_for_db_ids(self, db_ids):
res = []
def paths_for_db_ids(self, db_ids, as_map=False):
res = defaultdict(list) if as_map else []
for r,b in enumerate(self.db):
if b.application_id in db_ids:
res.append((r,b))
if as_map:
res[b.application_id].append(b)
else:
res.append((r,b))
return res
def get_collections_with_ids(self):