![]() |
#1 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
problems with LibraryDatabase2
I want to update the find duplicates plugin to use get_proxy_metadata instead of get_metadata, as per chaley's advice here. There is no problem doing this when comparing duplicates in one library. However problems arise when trying to find cross library duplicates. The original code by kiwidude initializes the target library as follows:
Code:
from calibre.library.database2 import LibraryDatabase2 self.target_db = LibraryDatabase2(self.library_path, read_only=True, is_second_db=True) Code:
AttributeError: 'LibraryDatabase2' object has no attribute 'new_api' Code:
from calibre.library import db as DB self.target_db = DB(self.library_path, read_only=True) |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
LibraryDatabase2 is obsolete. It works with the new database introduced in V4 because Kovid supplied a "legacy" replacement.
For all new code it is best to use something like this: Code:
def init_cache(library_path): from calibre.db.backend import DB from calibre.db.cache import Cache backend = DB(library_path) # other named parameters as needed cache = Cache(backend) cache.init() return cache For older code that uses methods in LibraryDatabase2, use something like this: Code:
from calibre.db.legacy import LibraryDatabase db = LibraryDatabase(library_path) # other named parameters as needed I think the new_api attribute might be available in LibraryDatabase2 through some sort of monkeypatching, but I am not sure of that. Last edited by chaley; 01-07-2021 at 12:58 PM. Reason: Changed parameter of LibraryDatabase |
![]() |
![]() |
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#4 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Thank you for the reply. What does the extra Cache(backend) do exactly? What would be the difference if I skipped it?
|
![]() |
![]() |
![]() |
#5 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#6 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#7 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
OK, got it. Thanks.
|
![]() |
![]() |
![]() |
#8 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,349
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The canonical way to do this is:
Code:
from calibre.library import db db = db('path/to/library/folder').new_api |
![]() |
![]() |
![]() |
#9 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Thanks, Kovid. Will do it that way.
|
![]() |
![]() |
![]() |
#10 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,349
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Lord knows, probably 2.0, possibly 1.0. No there is never a need to use the old interface in new code. It doesnt matter, you can alway use new_api, regardless of which interface it is. You can for instance do: db.new_api.new_api.new_api ad infinitum.
|
![]() |
![]() |
![]() |
#11 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Thanks.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Kindle 3G Keyboard WiFI Potential Fix For On-Off, Charging Problems/Screen Problems | Jim78 | Amazon Kindle | 0 | 09-25-2020 05:36 AM |
Connection problems on Windows, no problems on Linux LiveUSB | vM7iKtMlq9uWBBAK | Kobo Reader | 11 | 03-15-2019 10:17 AM |
Glo Problems after updating to software ver. 3.2.0 (Problems found unrelated to update) | Hiro-kun | Kobo Reader | 18 | 04-13-2014 06:38 PM |
full page image problems with iBooks/cover problems in iTunes | iain robinson | ePub | 1 | 06-28-2013 11:10 AM |
[Android App] Nexus 7 Problems? Mac Problems? | thetay24 | Devices | 4 | 08-31-2012 04:48 PM |