mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Get copy to library working witht he new library broker
This commit is contained in:
parent
2b6a7568d0
commit
2e84a2e1a9
@ -133,19 +133,20 @@ class Worker(Thread): # {{{
|
|||||||
def add_formats(self, id_, paths, newdb, replace=True):
|
def add_formats(self, id_, paths, newdb, replace=True):
|
||||||
for path in paths:
|
for path in paths:
|
||||||
fmt = os.path.splitext(path)[-1].replace('.', '').upper()
|
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,
|
newdb.add_format(id_, fmt, f, index_is_id=True,
|
||||||
notify=False, replace=replace)
|
notify=False, replace=replace)
|
||||||
|
|
||||||
def doit(self):
|
def doit(self):
|
||||||
from calibre.db.legacy import LibraryDatabase
|
from calibre.gui2.ui import get_gui
|
||||||
newdb = LibraryDatabase(self.loc, is_second_db=True)
|
library_broker = get_gui().library_broker
|
||||||
with closing(newdb):
|
newdb = library_broker.get_library(self.loc)
|
||||||
|
try:
|
||||||
if self.check_for_duplicates:
|
if self.check_for_duplicates:
|
||||||
self.find_identical_books_data = newdb.new_api.data_for_find_identical_books()
|
self.find_identical_books_data = newdb.new_api.data_for_find_identical_books()
|
||||||
self._doit(newdb)
|
self._doit(newdb)
|
||||||
newdb.break_cycles()
|
finally:
|
||||||
del newdb
|
library_broker.prune_loaded_dbs()
|
||||||
|
|
||||||
def _doit(self, newdb):
|
def _doit(self, newdb):
|
||||||
for i, x in enumerate(self.ids):
|
for i, x in enumerate(self.ids):
|
||||||
|
@ -127,6 +127,21 @@ class GuiLibraryBroker(LibraryBroker):
|
|||||||
finally:
|
finally:
|
||||||
self.last_used_times[library_id or self.default_library] = monotonic()
|
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):
|
def prepare_for_gui_library_change(self, newloc):
|
||||||
# Must be called with lock held
|
# Must be called with lock held
|
||||||
for library_id, path in self.lmap.iteritems():
|
for library_id, path in self.lmap.iteritems():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user