mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
More API
This commit is contained in:
parent
a49b518cde
commit
a57a355572
@ -294,6 +294,23 @@ class LibraryDatabase(object):
|
|||||||
book_id = index if index_is_id else self.id(index)
|
book_id = index if index_is_id else self.id(index)
|
||||||
return self.new_api.cover_last_modified(book_id) or self.last_modified()
|
return self.new_api.cover_last_modified(book_id) or self.last_modified()
|
||||||
|
|
||||||
|
def cover(self, index, index_is_id=False, as_file=False, as_image=False, as_path=False):
|
||||||
|
book_id = index if index_is_id else self.id(index)
|
||||||
|
return self.new_api.cover(book_id, as_file=as_file, as_image=as_image, as_path=as_path)
|
||||||
|
|
||||||
|
def copy_cover_to(self, index, dest, index_is_id=False, windows_atomic_move=None, use_hardlink=False):
|
||||||
|
book_id = index if index_is_id else self.id(index)
|
||||||
|
return self.new_api.copy_cover_to(book_id, dest, use_hardlink=use_hardlink)
|
||||||
|
|
||||||
|
def copy_format_to(self, index, fmt, dest, index_is_id=False, windows_atomic_move=None, use_hardlink=False):
|
||||||
|
book_id = index if index_is_id else self.id(index)
|
||||||
|
return self.new_api.copy_format_to(book_id, fmt, dest, use_hardlink=use_hardlink)
|
||||||
|
|
||||||
|
def delete_book(self, book_id, notify=True, commit=True, permanent=False, do_clean=True):
|
||||||
|
self.new_api.remove_books((book_id,), permanent=permanent)
|
||||||
|
if notify:
|
||||||
|
self.notify('delete', [id])
|
||||||
|
|
||||||
def authors_sort_strings(self, index, index_is_id=False):
|
def authors_sort_strings(self, index, index_is_id=False):
|
||||||
book_id = index if index_is_id else self.id(index)
|
book_id = index if index_is_id else self.id(index)
|
||||||
return list(self.new_api.author_sort_strings_for_books((book_id,))[book_id])
|
return list(self.new_api.author_sort_strings_for_books((book_id,))[book_id])
|
||||||
|
@ -164,6 +164,7 @@ class LegacyTest(BaseTest):
|
|||||||
for meth, args in {
|
for meth, args in {
|
||||||
'get_next_series_num_for': [('A Series One',)],
|
'get_next_series_num_for': [('A Series One',)],
|
||||||
'get_id_from_uuid':[('ddddd',), (db.uuid(1, True),)],
|
'get_id_from_uuid':[('ddddd',), (db.uuid(1, True),)],
|
||||||
|
'cover':[(0,), (1,), (2,)],
|
||||||
'get_author_id': [('author one',), ('unknown',), ('xxxxx',)],
|
'get_author_id': [('author one',), ('unknown',), ('xxxxx',)],
|
||||||
'series_id': [(0,), (1,), (2,)],
|
'series_id': [(0,), (1,), (2,)],
|
||||||
'publisher_id': [(0,), (1,), (2,)],
|
'publisher_id': [(0,), (1,), (2,)],
|
||||||
@ -231,6 +232,14 @@ class LegacyTest(BaseTest):
|
|||||||
for a in args:
|
for a in args:
|
||||||
self.assertEqual(fmt(getattr(db, meth)(*a)), fmt(getattr(ndb, meth)(*a)),
|
self.assertEqual(fmt(getattr(db, meth)(*a)), fmt(getattr(ndb, meth)(*a)),
|
||||||
'The method: %s() returned different results for argument %s' % (meth, a))
|
'The method: %s() returned different results for argument %s' % (meth, a))
|
||||||
|
d1, d2 = BytesIO(), BytesIO()
|
||||||
|
db.copy_cover_to(1, d1, True)
|
||||||
|
ndb.copy_cover_to(1, d2, True)
|
||||||
|
self.assertTrue(d1.getvalue() == d2.getvalue())
|
||||||
|
d1, d2 = BytesIO(), BytesIO()
|
||||||
|
db.copy_format_to(1, 'FMT1', d1, True)
|
||||||
|
ndb.copy_format_to(1, 'FMT1', d2, True)
|
||||||
|
self.assertTrue(d1.getvalue() == d2.getvalue())
|
||||||
db.close()
|
db.close()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
@ -275,7 +284,7 @@ class LegacyTest(BaseTest):
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def test_legacy_adding_books(self): # {{{
|
def test_legacy_adding_books(self): # {{{
|
||||||
'Test various adding books methods'
|
'Test various adding/deleting books methods'
|
||||||
from calibre.ebooks.metadata.book.base import Metadata
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
legacy, old = self.init_legacy(self.cloned_library), self.init_old(self.cloned_library)
|
legacy, old = self.init_legacy(self.cloned_library), self.init_old(self.cloned_library)
|
||||||
mi = Metadata('Added Book0', authors=('Added Author',))
|
mi = Metadata('Added Book0', authors=('Added Author',))
|
||||||
@ -332,6 +341,9 @@ class LegacyTest(BaseTest):
|
|||||||
self.assertEqual(cache.field_for('authors', bid), ('calibre',))
|
self.assertEqual(cache.field_for('authors', bid), ('calibre',))
|
||||||
self.assertEqual(cache.field_for('tags', bid), (_('News'), 'Events', 'one', 'two'))
|
self.assertEqual(cache.field_for('tags', bid), (_('News'), 'Events', 'one', 'two'))
|
||||||
|
|
||||||
|
legacy.delete_book(1)
|
||||||
|
old.delete_book(1)
|
||||||
|
self.assertNotIn(1, legacy.all_ids())
|
||||||
old.close()
|
old.close()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user