From 4a2a4a54d471731bdff97733f9605f24759230ef Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 12 Jul 2013 11:04:47 +0530 Subject: [PATCH] Add legacy add_format API --- src/calibre/db/legacy.py | 10 ++++++++++ src/calibre/db/tests/legacy.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index a12e949b55..e1e533266f 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -214,6 +214,16 @@ class LibraryDatabase(object): def add_news(self, 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 {{{ diff --git a/src/calibre/db/tests/legacy.py b/src/calibre/db/tests/legacy.py index dd9cbc2dc5..ced21f479d 100644 --- a/src/calibre/db/tests/legacy.py +++ b/src/calibre/db/tests/legacy.py @@ -7,6 +7,7 @@ __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' import inspect +from io import BytesIO from repr import repr from functools import partial from tempfile import NamedTemporaryFile @@ -166,6 +167,11 @@ class LegacyTest(BaseTest): 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.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: f.write(b'zzzz') f.flush()