Add legacy add_format API

This commit is contained in:
Kovid Goyal 2013-07-12 11:04:47 +05:30
parent f9bd87d785
commit 4a2a4a54d4
2 changed files with 16 additions and 0 deletions

View File

@ -214,6 +214,16 @@ class LibraryDatabase(object):
def add_news(self, path, arg): def add_news(self, path, arg):
return add_news(self.new_api, path, arg) return add_news(self.new_api, path, arg)
def add_format(self, index, fmt, stream, index_is_id=False, path=None, notify=True, replace=True, copy_function=None):
''' path and copy_function are ignored by the new API '''
book_id = index if index_is_id else self.data.index_to_id(index)
return self.new_api.add_format(book_id, fmt, stream, replace=replace, run_hooks=False, dbapi=self)
def add_format_with_hooks(self, index, fmt, fpath, index_is_id=False, path=None, notify=True, replace=True):
''' path is ignored by the new API '''
book_id = index if index_is_id else self.data.index_to_id(index)
return self.new_api.add_format(book_id, fmt, fpath, replace=replace, run_hooks=True, dbapi=self)
# }}} # }}}
# Custom data {{{ # Custom data {{{

View File

@ -7,6 +7,7 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import inspect import inspect
from io import BytesIO
from repr import repr from repr import repr
from functools import partial from functools import partial
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
@ -166,6 +167,11 @@ class LegacyTest(BaseTest):
book_id = T(kwargs={'preserve_uuid':True})(self) book_id = T(kwargs={'preserve_uuid':True})(self)
self.assertEqual(legacy.uuid(book_id, index_is_id=True), old.uuid(book_id, index_is_id=True)) self.assertEqual(legacy.uuid(book_id, index_is_id=True), old.uuid(book_id, index_is_id=True))
self.assertEqual(legacy.new_api.formats(book_id), ('AFF',)) self.assertEqual(legacy.new_api.formats(book_id), ('AFF',))
T = partial(ET, 'add_format', old=old, legacy=legacy)
T((0, 'AFF', BytesIO(b'fffff')))(self)
T((0, 'AFF', BytesIO(b'fffff')))(self)
T((0, 'AFF', BytesIO(b'fffff')), {'replace':True})(self)
with NamedTemporaryFile(suffix='.opf') as f: with NamedTemporaryFile(suffix='.opf') as f:
f.write(b'zzzz') f.write(b'zzzz')
f.flush() f.flush()