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:
Charles Haley 2010-05-17 10:48:47 +01:00
parent 1eabbcfb9a
commit 4201dbeeac
4 changed files with 20 additions and 9 deletions

View File

@ -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'
if path.endswith(os.sep):
self._main_prefix = path
else:
self._main_prefix = path + os.sep
self.booklist_class = BookList
self.is_connected = True

View File

@ -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)

View File

@ -113,7 +113,6 @@ class Device(DeviceConfig, DevicePlugin):
def _windows_space(cls, prefix):
if not prefix:
return 0, 0
if prefix.endswith(os.sep):
prefix = prefix[:-1]
win32file = __import__('win32file', globals(), locals(), [], -1)
try:

View File

@ -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,10 +107,15 @@ 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 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:
@ -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))