mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:Pass metadata to upload_books method in device drivers when uploading books using the GUI
This commit is contained in:
parent
17df10b5a2
commit
1c1414d11a
@ -123,7 +123,8 @@ class Device(object):
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def upload_books(self, files, names, on_card=False, end_session=True):
|
||||
def upload_books(self, files, names, on_card=False, end_session=True,
|
||||
metadata=None):
|
||||
'''
|
||||
Upload a list of books to the device. If a file already
|
||||
exists on the device, it should be replaced.
|
||||
@ -135,6 +136,10 @@ class Device(object):
|
||||
once uploaded to the device. len(names) == len(files)
|
||||
@return: A list of 3-element tuples. The list is meant to be passed
|
||||
to L{add_books_to_metadata}.
|
||||
@param metadata: If not None, it is a list of dictionaries. Each dictionary
|
||||
will have at least the key tags to allow the driver to choose book location
|
||||
based on tags. len(metadata) == len(files). If your device does not support
|
||||
hierarchical ebook folders, you can safely ignore this parameter.
|
||||
'''
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -841,7 +841,8 @@ class PRS500(Device):
|
||||
self.upload_book_list(booklists[1], end_session=False)
|
||||
|
||||
@safe
|
||||
def upload_books(self, files, names, on_card=False, end_session=True):
|
||||
def upload_books(self, files, names, on_card=False, end_session=True,
|
||||
metadata=None):
|
||||
card = self.card(end_session=False)
|
||||
prefix = card + '/' + self.CARD_PATH_PREFIX +'/' if on_card else '/Data/media/books/'
|
||||
if on_card and not self._exists(prefix)[0]:
|
||||
|
@ -407,7 +407,8 @@ class PRS505(Device):
|
||||
if not os.path.isdir(path):
|
||||
os.utime(path, None)
|
||||
|
||||
def upload_books(self, files, names, on_card=False, end_session=True):
|
||||
def upload_books(self, files, names, on_card=False, end_session=True,
|
||||
metadata=None):
|
||||
if on_card and not self._card_prefix:
|
||||
raise ValueError(_('The reader has no storage card connected.'))
|
||||
path = os.path.join(self._card_prefix, self.CARD_PATH_PREFIX) if on_card \
|
||||
|
@ -48,7 +48,8 @@ class USBMS(Device):
|
||||
bl.append(Book(os.path.join(path, filename), title, author, mime))
|
||||
return bl
|
||||
|
||||
def upload_books(self, files, names, on_card=False, end_session=True):
|
||||
def upload_books(self, files, names, on_card=False, end_session=True,
|
||||
metadata=None):
|
||||
if on_card and not self._card_prefix:
|
||||
raise ValueError(_('The reader has no storage card connected.'))
|
||||
|
||||
|
@ -136,16 +136,18 @@ class DeviceManager(Thread):
|
||||
return self.create_job(self._sync_booklists, done, args=[booklists],
|
||||
description=_('Send metadata to device'))
|
||||
|
||||
def _upload_books(self, files, names, on_card=False):
|
||||
def _upload_books(self, files, names, on_card=False, metadata=None):
|
||||
'''Upload books to device: '''
|
||||
return self.device.upload_books(files, names, on_card, end_session=False)
|
||||
return self.device.upload_books(files, names, on_card,
|
||||
metadata=metadata, end_session=False)
|
||||
|
||||
def upload_books(self, done, files, names, on_card=False, titles=None):
|
||||
def upload_books(self, done, files, names, on_card=False, titles=None,
|
||||
metadata=None):
|
||||
desc = _('Upload %d books to device')%len(names)
|
||||
if titles:
|
||||
desc += u':' + u', '.join(titles)
|
||||
return self.create_job(self._upload_books, done, args=[files, names],
|
||||
kwargs={'on_card':on_card}, description=desc)
|
||||
kwargs={'on_card':on_card,'metadata':metadata}, description=desc)
|
||||
|
||||
def add_books_to_metadata(self, locations, metadata, booklists):
|
||||
self.device.add_books_to_metadata(locations, metadata, booklists)
|
||||
|
@ -745,8 +745,8 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
'''
|
||||
titles = [i['title'] for i in metadata]
|
||||
job = self.device_manager.upload_books(Dispatcher(self.books_uploaded),
|
||||
files, names, on_card=on_card,
|
||||
titles=titles
|
||||
files, names, on_card=on_card,
|
||||
metadata=metadata, titles=titles
|
||||
)
|
||||
self.upload_memory[job] = (metadata, on_card, memory, files)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user