mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
1) changes to ondevice scan to use Kovid's iterator
2) correction to path construction in USMBS
This commit is contained in:
parent
d29cfd266f
commit
1e90881b90
@ -190,8 +190,8 @@ class USBMS(CLI, Device):
|
|||||||
print 'in add_books_to_metadata. Prefix is None!', path, self._main_prefix
|
print 'in add_books_to_metadata. Prefix is None!', path, self._main_prefix
|
||||||
continue
|
continue
|
||||||
lpath = path.partition(prefix)[2]
|
lpath = path.partition(prefix)[2]
|
||||||
if lpath.startswith(os.sep):
|
if lpath.startswith('/') or lpath.startswith('\\'):
|
||||||
lpath = lpath[len(os.sep):]
|
lpath = lpath[1:]
|
||||||
book = self.book_class(prefix, lpath, other=info)
|
book = self.book_class(prefix, lpath, other=info)
|
||||||
if book.size is None:
|
if book.size is None:
|
||||||
book.size = os.stat(self.normalize_path(path)).st_size
|
book.size = os.stat(self.normalize_path(path)).st_size
|
||||||
|
@ -1091,16 +1091,8 @@ class DeviceGUI(object):
|
|||||||
self.db_book_title_cache = {}
|
self.db_book_title_cache = {}
|
||||||
self.db_book_uuid_cache = set()
|
self.db_book_uuid_cache = set()
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
# The following is a terrible hack, made necessary because the db
|
for id in db.data.iterallids():
|
||||||
# result_cache will always use the results filtered by the current
|
mi = db.get_metadata(id, index_is_id=True)
|
||||||
# search. We need all the db entries here. Choice was to either
|
|
||||||
# cache the search results so we can use the entire db, to duplicate
|
|
||||||
# large parts of the get_metadata code, or to use db_ids and pay the
|
|
||||||
# large performance penalty of zillions of SQL queries. Choice:
|
|
||||||
# save/restore the search state.
|
|
||||||
state = db.get_state_before_scan()
|
|
||||||
for idx in range(db.count()):
|
|
||||||
mi = db.get_metadata(idx, index_is_id=False)
|
|
||||||
title = re.sub('(?u)\W|[_]', '', mi.title.lower())
|
title = re.sub('(?u)\W|[_]', '', mi.title.lower())
|
||||||
if title not in self.db_book_title_cache:
|
if title not in self.db_book_title_cache:
|
||||||
self.db_book_title_cache[title] = {'authors':{}, 'db_ids':{}}
|
self.db_book_title_cache[title] = {'authors':{}, 'db_ids':{}}
|
||||||
@ -1109,7 +1101,6 @@ class DeviceGUI(object):
|
|||||||
self.db_book_title_cache[title]['authors'][authors] = mi
|
self.db_book_title_cache[title]['authors'][authors] = mi
|
||||||
self.db_book_title_cache[title]['db_ids'][mi.application_id] = mi
|
self.db_book_title_cache[title]['db_ids'][mi.application_id] = mi
|
||||||
self.db_book_uuid_cache.add(mi.uuid)
|
self.db_book_uuid_cache.add(mi.uuid)
|
||||||
db.restore_state_after_scan(state)
|
|
||||||
|
|
||||||
# Now iterate through all the books on the device, setting the
|
# Now iterate through all the books on the device, setting the
|
||||||
# in_library field Fastest and most accurate key is the uuid. Second is
|
# in_library field Fastest and most accurate key is the uuid. Second is
|
||||||
|
@ -563,14 +563,6 @@ class ResultCache(SearchQueryParser):
|
|||||||
if item is not None:
|
if item is not None:
|
||||||
item[ondevice_col] = db.book_on_device_string(item[0])
|
item[ondevice_col] = db.book_on_device_string(item[0])
|
||||||
|
|
||||||
def get_state_before_scan(self):
|
|
||||||
retval = self._map_filtered
|
|
||||||
self._map_filtered = self._map
|
|
||||||
return retval
|
|
||||||
|
|
||||||
def restore_state_after_scan(self, map_filtered):
|
|
||||||
self._map_filtered = map_filtered
|
|
||||||
|
|
||||||
def refresh(self, db, field=None, ascending=True):
|
def refresh(self, db, field=None, ascending=True):
|
||||||
temp = db.conn.get('SELECT * FROM meta2')
|
temp = db.conn.get('SELECT * FROM meta2')
|
||||||
self._data = list(itertools.repeat(None, temp[-1][0]+2)) if temp else []
|
self._data = list(itertools.repeat(None, temp[-1][0]+2)) if temp else []
|
||||||
|
@ -245,8 +245,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.has_id = self.data.has_id
|
self.has_id = self.data.has_id
|
||||||
self.count = self.data.count
|
self.count = self.data.count
|
||||||
|
|
||||||
self.get_state_before_scan = self.data.get_state_before_scan
|
|
||||||
self.restore_state_after_scan = self.data.restore_state_after_scan
|
|
||||||
self.refresh_ondevice = functools.partial(self.data.refresh_ondevice, self)
|
self.refresh_ondevice = functools.partial(self.data.refresh_ondevice, self)
|
||||||
|
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user