mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Changes to usbms to use correct booklist.add_book api
This commit is contained in:
parent
f6f028ee5c
commit
3047defba9
@ -117,7 +117,8 @@ class BookList(_BookList):
|
||||
def add_book(self, book, replace_metadata):
|
||||
if book not in self:
|
||||
self.append(book)
|
||||
return False # subclasses return True if device metadata has changed
|
||||
return True
|
||||
return False
|
||||
|
||||
def remove_book(self, book):
|
||||
self.remove(book)
|
||||
|
@ -66,16 +66,14 @@ class USBMS(CLI, Device):
|
||||
self.EBOOK_DIR_CARD_B if oncard == 'cardb' else \
|
||||
self.get_main_ebook_dir()
|
||||
|
||||
# build a temporary list of books from the metadata cache
|
||||
bl, need_sync = self.parse_metadata_cache(prefix, self.METADATA_CACHE)
|
||||
# get the metadata cache
|
||||
bl = self.booklist_class(oncard, prefix, self.settings)
|
||||
need_sync = self.parse_metadata_cache(bl, prefix, self.METADATA_CACHE)
|
||||
|
||||
# make a dict cache of paths so the lookup in the loop below is faster.
|
||||
bl_cache = {}
|
||||
for idx,b in enumerate(bl):
|
||||
bl_cache[b.lpath] = idx
|
||||
self.count_found_in_bl = 0
|
||||
|
||||
# Make the real booklist that will be filled in below
|
||||
metadata = self.booklist_class(oncard, prefix, self.settings)
|
||||
|
||||
def update_booklist(filename, path, prefix):
|
||||
changed = False
|
||||
@ -86,12 +84,13 @@ class USBMS(CLI, Device):
|
||||
lpath = lpath[len(os.sep):]
|
||||
idx = bl_cache.get(lpath.replace('\\', '/'), None)
|
||||
if idx is not None:
|
||||
item, changed = self.update_metadata_item(bl[idx])
|
||||
self.count_found_in_bl += 1
|
||||
else:
|
||||
item = self.book_from_path(prefix, lpath)
|
||||
if self.update_metadata_item(bl[idx]):
|
||||
#print 'update_metadata_item returned true'
|
||||
changed = True
|
||||
if metadata.add_book(item, replace_metadata=False):
|
||||
bl_cache[lpath.replace('\\', '/')] = None
|
||||
else:
|
||||
if bl.add_book(self.book_from_path(prefix, lpath),
|
||||
replace_metadata=False):
|
||||
changed = True
|
||||
except: # Probably a filename encoding error
|
||||
import traceback
|
||||
@ -126,23 +125,23 @@ class USBMS(CLI, Device):
|
||||
if changed:
|
||||
need_sync = True
|
||||
|
||||
# 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.
|
||||
for val in bl_cache.itervalues():
|
||||
if val is not None:
|
||||
need_sync = True
|
||||
del bl[val]
|
||||
|
||||
#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:
|
||||
#print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \
|
||||
# (len(bl_cache), len(bl), need_sync)
|
||||
if need_sync: #self.count_found_in_bl != len(bl) or need_sync:
|
||||
if oncard == 'cardb':
|
||||
self.sync_booklists((None, None, metadata))
|
||||
self.sync_booklists((None, None, bl))
|
||||
elif oncard == 'carda':
|
||||
self.sync_booklists((None, metadata, None))
|
||||
self.sync_booklists((None, bl, None))
|
||||
else:
|
||||
self.sync_booklists((metadata, None, None))
|
||||
self.sync_booklists((bl, None, None))
|
||||
|
||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
||||
return metadata
|
||||
return bl
|
||||
|
||||
def upload_books(self, files, names, on_card=None, end_session=True,
|
||||
metadata=None):
|
||||
@ -273,8 +272,8 @@ class USBMS(CLI, Device):
|
||||
return path
|
||||
|
||||
@classmethod
|
||||
def parse_metadata_cache(cls, prefix, name):
|
||||
bl = []
|
||||
def parse_metadata_cache(cls, bl, prefix, name):
|
||||
# bl = cls.booklist_class()
|
||||
js = []
|
||||
need_sync = False
|
||||
try:
|
||||
@ -290,18 +289,18 @@ class USBMS(CLI, Device):
|
||||
traceback.print_exc()
|
||||
bl = []
|
||||
need_sync = True
|
||||
return bl, need_sync
|
||||
return need_sync
|
||||
|
||||
@classmethod
|
||||
def update_metadata_item(cls, item):
|
||||
def update_metadata_item(cls, book):
|
||||
changed = False
|
||||
size = os.stat(cls.normalize_path(item.path)).st_size
|
||||
if size != item.size:
|
||||
size = os.stat(cls.normalize_path(book.path)).st_size
|
||||
if size != book.size:
|
||||
changed = True
|
||||
mi = cls.metadata_from_path(item.path)
|
||||
item.smart_update(mi)
|
||||
item.size = size
|
||||
return item, changed
|
||||
mi = cls.metadata_from_path(book.path)
|
||||
book.smart_update(mi)
|
||||
book.size = size
|
||||
return changed
|
||||
|
||||
@classmethod
|
||||
def metadata_from_path(cls, path):
|
||||
|
@ -2,18 +2,18 @@
|
||||
# Invoke with nmake /f Makefile.winutil
|
||||
|
||||
test : winutil.pyd
|
||||
python.exe -c "import winutil; winutil.set_debug(True); print repr(winutil.strftime(u'%b %a %A')); "
|
||||
\python26\python.exe -c "import winutil; winutil.set_debug(True); print repr(winutil.strftime(u'%b %a %A')); "
|
||||
#python.exe -c "import winutil; winutil.set_debug(True); print winutil.get_usb_devices(); print winutil.get_mounted_volumes_for_usb_device(0x054c, 0x031e)"
|
||||
|
||||
winutil.pyd : winutil.obj
|
||||
link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:c:\Python25\libs \
|
||||
/LIBPATH:c:\Python25\PCBuild shell32.lib setupapi.lib /EXPORT:initwinutil \
|
||||
link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:c:\Python26\libs \
|
||||
/LIBPATH:c:\Python26\PCBuild shell32.lib setupapi.lib Wininet.lib /EXPORT:initwinutil \
|
||||
winutil.obj /OUT:winutil.pyd
|
||||
|
||||
|
||||
winutil.obj : winutil.c
|
||||
cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -Ic:\Python25\include \
|
||||
-Ic:\Python25\PC -Ic:\WinDDK\6001.18001\inc\api /Tcwinutil.c /Fowinutil.obj
|
||||
cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -Ic:\Python26\include \
|
||||
-Ic:\Python26\PC -Ic:\WinDDK\6001.18001\inc\api /Tcwinutil.c /Fowinutil.obj
|
||||
|
||||
clean :
|
||||
del winutil.pyd winutil.obj winutil.exp winutil.lib
|
||||
|
Loading…
x
Reference in New Issue
Block a user