Get copy to library working witht he new library broker

This commit is contained in:
Kovid Goyal 2017-04-10 16:14:07 +05:30
parent 2b6a7568d0
commit 2e84a2e1a9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 22 additions and 6 deletions

View File

@ -133,19 +133,20 @@ class Worker(Thread): # {{{
def add_formats(self, id_, paths, newdb, replace=True):
for path in paths:
fmt = os.path.splitext(path)[-1].replace('.', '').upper()
with open(path, 'rb') as f:
with lopen(path, 'rb') as f:
newdb.add_format(id_, fmt, f, index_is_id=True,
notify=False, replace=replace)
def doit(self):
from calibre.db.legacy import LibraryDatabase
newdb = LibraryDatabase(self.loc, is_second_db=True)
with closing(newdb):
from calibre.gui2.ui import get_gui
library_broker = get_gui().library_broker
newdb = library_broker.get_library(self.loc)
try:
if self.check_for_duplicates:
self.find_identical_books_data = newdb.new_api.data_for_find_identical_books()
self._doit(newdb)
newdb.break_cycles()
del newdb
finally:
library_broker.prune_loaded_dbs()
def _doit(self, newdb):
for i, x in enumerate(self.ids):

View File

@ -127,6 +127,21 @@ class GuiLibraryBroker(LibraryBroker):
finally:
self.last_used_times[library_id or self.default_library] = monotonic()
def get_library(self, library_path):
library_path = canonicalize_path(library_path)
with self:
for library_id, path in self.lmap.iteritems():
if samefile(library_path, path):
db = self.loaded_dbs.get(library_id)
if db is None:
db = self.loaded_dbs[library_id] = self.init_library(path, False)
return db
db = self.init_library(library_path, False)
library_id = library_id_from_path(library_path, self.lmap)
self.lmap[library_id] = library_path
self.loaded_dbs[library_id] = db
return db
def prepare_for_gui_library_change(self, newloc):
# Must be called with lock held
for library_id, path in self.lmap.iteritems():