Allow default library to work even with library removals

This commit is contained in:
Kovid Goyal 2017-04-13 10:57:25 +05:30
parent 0ae992a841
commit dd3150d975
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -57,17 +57,15 @@ class LibraryBroker(object):
def __init__(self, libraries): def __init__(self, libraries):
self.lock = Lock() self.lock = Lock()
self.lmap = {} self.lmap = OrderedDict()
seen = set() seen = set()
for i, path in enumerate(canonicalize_path(p) for p in libraries): for path in (canonicalize_path(p) for p in libraries):
if path in seen: if path in seen:
continue continue
seen.add(path) seen.add(path)
if not LibraryDatabase.exists_at(path): if not LibraryDatabase.exists_at(path):
continue continue
library_id = library_id_from_path(path, self.lmap) library_id = library_id_from_path(path, self.lmap)
if i == 0:
self.default_library = library_id
self.lmap[library_id] = path self.lmap[library_id] = path
self.loaded_dbs = {} self.loaded_dbs = {}
self.category_caches, self.search_caches, self.tag_browser_caches = ( self.category_caches, self.search_caches, self.tag_browser_caches = (
@ -98,7 +96,11 @@ class LibraryBroker(object):
with self: with self:
for db in self.loaded_dbs.itervalues(): for db in self.loaded_dbs.itervalues():
getattr(db, 'close', lambda: None)() getattr(db, 'close', lambda: None)()
self.lmap, self.loaded_dbs = {}, {} self.lmap, self.loaded_dbs = OrderedDict(), {}
@property
def default_library(self):
return next(self.lmap.iterkeys())
@property @property
def library_map(self): def library_map(self):