mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
1) Ensure that folder_device prefix (the path) end in os.sep
2) Fix regression causing sync of metadata cache on every connect 3) Report correct progress when adding books
This commit is contained in:
parent
1eabbcfb9a
commit
4201dbeeac
@ -54,7 +54,10 @@ class FOLDER_DEVICE(USBMS):
|
||||
def __init__(self, path):
|
||||
if not os.path.isdir(path):
|
||||
raise IOError, 'Path is not a folder'
|
||||
self._main_prefix = path
|
||||
if path.endswith(os.sep):
|
||||
self._main_prefix = path
|
||||
else:
|
||||
self._main_prefix = path + os.sep
|
||||
self.booklist_class = BookList
|
||||
self.is_connected = True
|
||||
|
||||
|
@ -117,7 +117,7 @@ class BookList(_BookList):
|
||||
def add_book(self, book, replace_metadata):
|
||||
if book not in self:
|
||||
self.append(book)
|
||||
return True
|
||||
return False # subclasses return True if device metadata has changed
|
||||
|
||||
def remove_book(self, book):
|
||||
self.remove(book)
|
||||
|
@ -113,8 +113,7 @@ class Device(DeviceConfig, DevicePlugin):
|
||||
def _windows_space(cls, prefix):
|
||||
if not prefix:
|
||||
return 0, 0
|
||||
if prefix.endswith(os.sep):
|
||||
prefix = prefix[:-1]
|
||||
prefix = prefix[:-1]
|
||||
win32file = __import__('win32file', globals(), locals(), [], -1)
|
||||
try:
|
||||
sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \
|
||||
|
@ -90,6 +90,7 @@ class USBMS(CLI, Device):
|
||||
self.count_found_in_bl += 1
|
||||
else:
|
||||
item = self.book_from_path(prefix, lpath)
|
||||
changed = True
|
||||
if metadata.add_book(item, replace_metadata=False):
|
||||
changed = True
|
||||
except: # Probably a filename encoding error
|
||||
@ -106,12 +107,17 @@ class USBMS(CLI, Device):
|
||||
if not os.path.exists(ebook_dir): continue
|
||||
# Get all books in the ebook_dir directory
|
||||
if self.SUPPORTS_SUB_DIRS:
|
||||
# build a list of files to check, so we can accurately report progress
|
||||
flist = []
|
||||
for path, dirs, files in os.walk(ebook_dir):
|
||||
for filename in files:
|
||||
self.report_progress(0.5, _('Getting list of books on device...'))
|
||||
changed = update_booklist(filename, path, prefix)
|
||||
if changed:
|
||||
need_sync = True
|
||||
if filename != self.METADATA_CACHE:
|
||||
flist.append({'filename':filename, 'path': path})
|
||||
for i, f in enumerate(flist):
|
||||
self.report_progress(i/float(len(flist)), _('Getting list of books on device...'))
|
||||
changed = update_booklist(f['filename'], f['path'], prefix)
|
||||
if changed:
|
||||
need_sync = True
|
||||
else:
|
||||
paths = os.listdir(ebook_dir)
|
||||
for i, filename in enumerate(paths):
|
||||
@ -123,7 +129,10 @@ class USBMS(CLI, Device):
|
||||
# if count != len(bl) then there were items in it that we did not
|
||||
# find on the device. If need_sync is True then there were either items
|
||||
# on the device that were not in bl or some of the items were changed.
|
||||
#print "count found in cache: %d, count of files in cache: %d, must_sync_cache: %s" % (self.count_found_in_bl, len(bl), need_sync)
|
||||
|
||||
#print "count found in cache: %d, count of files in cache: %d, need_sync: %s, must_sync_cache: %s" % \
|
||||
# (self.count_found_in_bl, len(bl), need_sync,
|
||||
# need_sync or self.count_found_in_bl != len(bl))
|
||||
if self.count_found_in_bl != len(bl) or need_sync:
|
||||
if oncard == 'cardb':
|
||||
self.sync_booklists((None, None, metadata))
|
||||
|
Loading…
x
Reference in New Issue
Block a user