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):
|
def add_book(self, book, replace_metadata):
|
||||||
if book not in self:
|
if book not in self:
|
||||||
self.append(book)
|
self.append(book)
|
||||||
return False # subclasses return True if device metadata has changed
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def remove_book(self, book):
|
def remove_book(self, book):
|
||||||
self.remove(book)
|
self.remove(book)
|
||||||
|
@ -66,16 +66,14 @@ class USBMS(CLI, Device):
|
|||||||
self.EBOOK_DIR_CARD_B if oncard == 'cardb' else \
|
self.EBOOK_DIR_CARD_B if oncard == 'cardb' else \
|
||||||
self.get_main_ebook_dir()
|
self.get_main_ebook_dir()
|
||||||
|
|
||||||
# build a temporary list of books from the metadata cache
|
# get the metadata cache
|
||||||
bl, need_sync = self.parse_metadata_cache(prefix, self.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.
|
# make a dict cache of paths so the lookup in the loop below is faster.
|
||||||
bl_cache = {}
|
bl_cache = {}
|
||||||
for idx,b in enumerate(bl):
|
for idx,b in enumerate(bl):
|
||||||
bl_cache[b.lpath] = idx
|
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):
|
def update_booklist(filename, path, prefix):
|
||||||
changed = False
|
changed = False
|
||||||
@ -86,13 +84,14 @@ class USBMS(CLI, Device):
|
|||||||
lpath = lpath[len(os.sep):]
|
lpath = lpath[len(os.sep):]
|
||||||
idx = bl_cache.get(lpath.replace('\\', '/'), None)
|
idx = bl_cache.get(lpath.replace('\\', '/'), None)
|
||||||
if idx is not None:
|
if idx is not None:
|
||||||
item, changed = self.update_metadata_item(bl[idx])
|
if self.update_metadata_item(bl[idx]):
|
||||||
self.count_found_in_bl += 1
|
#print 'update_metadata_item returned true'
|
||||||
|
changed = True
|
||||||
|
bl_cache[lpath.replace('\\', '/')] = None
|
||||||
else:
|
else:
|
||||||
item = self.book_from_path(prefix, lpath)
|
if bl.add_book(self.book_from_path(prefix, lpath),
|
||||||
changed = True
|
replace_metadata=False):
|
||||||
if metadata.add_book(item, replace_metadata=False):
|
changed = True
|
||||||
changed = True
|
|
||||||
except: # Probably a filename encoding error
|
except: # Probably a filename encoding error
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
@ -126,23 +125,23 @@ class USBMS(CLI, Device):
|
|||||||
if changed:
|
if changed:
|
||||||
need_sync = True
|
need_sync = True
|
||||||
|
|
||||||
# if count != len(bl) then there were items in it that we did not
|
for val in bl_cache.itervalues():
|
||||||
# find on the device. If need_sync is True then there were either items
|
if val is not None:
|
||||||
# on the device that were not in bl or some of the items were changed.
|
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" % \
|
#print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \
|
||||||
# (self.count_found_in_bl, len(bl), need_sync,
|
# (len(bl_cache), len(bl), need_sync)
|
||||||
# need_sync or self.count_found_in_bl != len(bl))
|
if need_sync: #self.count_found_in_bl != len(bl) or need_sync:
|
||||||
if self.count_found_in_bl != len(bl) or need_sync:
|
|
||||||
if oncard == 'cardb':
|
if oncard == 'cardb':
|
||||||
self.sync_booklists((None, None, metadata))
|
self.sync_booklists((None, None, bl))
|
||||||
elif oncard == 'carda':
|
elif oncard == 'carda':
|
||||||
self.sync_booklists((None, metadata, None))
|
self.sync_booklists((None, bl, None))
|
||||||
else:
|
else:
|
||||||
self.sync_booklists((metadata, None, None))
|
self.sync_booklists((bl, None, None))
|
||||||
|
|
||||||
self.report_progress(1.0, _('Getting list of books on device...'))
|
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,
|
def upload_books(self, files, names, on_card=None, end_session=True,
|
||||||
metadata=None):
|
metadata=None):
|
||||||
@ -273,8 +272,8 @@ class USBMS(CLI, Device):
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_metadata_cache(cls, prefix, name):
|
def parse_metadata_cache(cls, bl, prefix, name):
|
||||||
bl = []
|
# bl = cls.booklist_class()
|
||||||
js = []
|
js = []
|
||||||
need_sync = False
|
need_sync = False
|
||||||
try:
|
try:
|
||||||
@ -290,18 +289,18 @@ class USBMS(CLI, Device):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
bl = []
|
bl = []
|
||||||
need_sync = True
|
need_sync = True
|
||||||
return bl, need_sync
|
return need_sync
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_metadata_item(cls, item):
|
def update_metadata_item(cls, book):
|
||||||
changed = False
|
changed = False
|
||||||
size = os.stat(cls.normalize_path(item.path)).st_size
|
size = os.stat(cls.normalize_path(book.path)).st_size
|
||||||
if size != item.size:
|
if size != book.size:
|
||||||
changed = True
|
changed = True
|
||||||
mi = cls.metadata_from_path(item.path)
|
mi = cls.metadata_from_path(book.path)
|
||||||
item.smart_update(mi)
|
book.smart_update(mi)
|
||||||
item.size = size
|
book.size = size
|
||||||
return item, changed
|
return changed
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def metadata_from_path(cls, path):
|
def metadata_from_path(cls, path):
|
||||||
|
@ -2,18 +2,18 @@
|
|||||||
# Invoke with nmake /f Makefile.winutil
|
# Invoke with nmake /f Makefile.winutil
|
||||||
|
|
||||||
test : winutil.pyd
|
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)"
|
#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
|
winutil.pyd : winutil.obj
|
||||||
link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:c:\Python25\libs \
|
link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:c:\Python26\libs \
|
||||||
/LIBPATH:c:\Python25\PCBuild shell32.lib setupapi.lib /EXPORT:initwinutil \
|
/LIBPATH:c:\Python26\PCBuild shell32.lib setupapi.lib Wininet.lib /EXPORT:initwinutil \
|
||||||
winutil.obj /OUT:winutil.pyd
|
winutil.obj /OUT:winutil.pyd
|
||||||
|
|
||||||
|
|
||||||
winutil.obj : winutil.c
|
winutil.obj : winutil.c
|
||||||
cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -Ic:\Python25\include \
|
cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -Ic:\Python26\include \
|
||||||
-Ic:\Python25\PC -Ic:\WinDDK\6001.18001\inc\api /Tcwinutil.c /Fowinutil.obj
|
-Ic:\Python26\PC -Ic:\WinDDK\6001.18001\inc\api /Tcwinutil.c /Fowinutil.obj
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
del winutil.pyd winutil.obj winutil.exp winutil.lib
|
del winutil.pyd winutil.obj winutil.exp winutil.lib
|
||||||
|
Loading…
x
Reference in New Issue
Block a user