mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
9038754c71
@ -682,30 +682,36 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _metadata_in_cache(self, uuid, ext, lastmod):
|
def _metadata_in_cache(self, uuid, ext, lastmod):
|
||||||
if lastmod == 'None':
|
try:
|
||||||
return None
|
from calibre.utils.date import parse_date, now
|
||||||
from calibre.utils.date import parse_date, now
|
key = uuid+ext
|
||||||
key = uuid+ext
|
if isinstance(lastmod, unicode):
|
||||||
if isinstance(lastmod, unicode):
|
if lastmod == 'None':
|
||||||
lastmod = parse_date(lastmod)
|
return None
|
||||||
if key in self.known_uuids and self.known_uuids[key]['book'].last_modified == lastmod:
|
lastmod = parse_date(lastmod)
|
||||||
self.known_uuids[key]['last_used'] = now()
|
if key in self.known_uuids and self.known_uuids[key]['book'].last_modified == lastmod:
|
||||||
return self.known_uuids[key]['book'].deepcopy()
|
self.known_uuids[key]['last_used'] = now()
|
||||||
|
return self.known_uuids[key]['book'].deepcopy()
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _metadata_already_on_device(self, book):
|
def _metadata_already_on_device(self, book):
|
||||||
v = self.known_metadata.get(book.lpath, None)
|
try:
|
||||||
if v is not None:
|
v = self.known_metadata.get(book.lpath, None)
|
||||||
# Metadata is the same if the uuids match, if the last_modified dates
|
if v is not None:
|
||||||
# match, and if the height of the thumbnails is the same. The last
|
# Metadata is the same if the uuids match, if the last_modified dates
|
||||||
# is there to allow a device to demand a different thumbnail size
|
# match, and if the height of the thumbnails is the same. The last
|
||||||
if (v.get('uuid', None) == book.get('uuid', None) and
|
# is there to allow a device to demand a different thumbnail size
|
||||||
v.get('last_modified', None) == book.get('last_modified', None)):
|
if (v.get('uuid', None) == book.get('uuid', None) and
|
||||||
v_thumb = v.get('thumbnail', None)
|
v.get('last_modified', None) == book.get('last_modified', None)):
|
||||||
b_thumb = book.get('thumbnail', None)
|
v_thumb = v.get('thumbnail', None)
|
||||||
if bool(v_thumb) != bool(b_thumb):
|
b_thumb = book.get('thumbnail', None)
|
||||||
return False
|
if bool(v_thumb) != bool(b_thumb):
|
||||||
return not v_thumb or v_thumb[1] == b_thumb[1]
|
return False
|
||||||
|
return not v_thumb or v_thumb[1] == b_thumb[1]
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _uuid_already_on_device(self, uuid, ext):
|
def _uuid_already_on_device(self, uuid, ext):
|
||||||
@ -730,9 +736,9 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
'_metadata_cache.json')
|
'_metadata_cache.json')
|
||||||
self.known_uuids = defaultdict(dict)
|
self.known_uuids = defaultdict(dict)
|
||||||
self.known_metadata = {}
|
self.known_metadata = {}
|
||||||
if os.path.exists(cache_file_name):
|
try:
|
||||||
with open(cache_file_name, mode='rb') as fd:
|
if os.path.exists(cache_file_name):
|
||||||
try:
|
with open(cache_file_name, mode='rb') as fd:
|
||||||
while True:
|
while True:
|
||||||
rec_len = fd.readline()
|
rec_len = fd.readline()
|
||||||
if len(rec_len) != 8:
|
if len(rec_len) != 8:
|
||||||
@ -750,16 +756,24 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
self.known_uuids.pop(uuid, None)
|
self.known_uuids.pop(uuid, None)
|
||||||
else:
|
else:
|
||||||
self.known_metadata[lpath] = metadata
|
self.known_metadata[lpath] = metadata
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
self.known_uuids = defaultdict(dict)
|
||||||
|
self.known_metadata = {}
|
||||||
|
try:
|
||||||
|
if os.path.exists(cache_file_name):
|
||||||
|
os.remove(cache_file_name)
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
def _write_metadata_cache(self):
|
def _write_metadata_cache(self):
|
||||||
from calibre.utils.config import to_json
|
from calibre.utils.config import to_json
|
||||||
cache_file_name = os.path.join(cache_dir(),
|
cache_file_name = os.path.join(cache_dir(),
|
||||||
'device_drivers_' + self.__class__.__name__ +
|
'device_drivers_' + self.__class__.__name__ +
|
||||||
'_metadata_cache.json')
|
'_metadata_cache.json')
|
||||||
with open(cache_file_name, mode='wb') as fd:
|
try:
|
||||||
try:
|
with open(cache_file_name, mode='wb') as fd:
|
||||||
for uuid,book in self.known_uuids.iteritems():
|
for uuid,book in self.known_uuids.iteritems():
|
||||||
json_metadata = defaultdict(dict)
|
json_metadata = defaultdict(dict)
|
||||||
json_metadata[uuid]['book'] = self.json_codec.encode_book_metadata(book['book'])
|
json_metadata[uuid]['book'] = self.json_codec.encode_book_metadata(book['book'])
|
||||||
@ -768,6 +782,11 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
fd.write("%0.7d\n"%(len(result)+1))
|
fd.write("%0.7d\n"%(len(result)+1))
|
||||||
fd.write(result)
|
fd.write(result)
|
||||||
fd.write('\n')
|
fd.write('\n')
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
try:
|
||||||
|
if os.path.exists(cache_file_name):
|
||||||
|
os.remove(cache_file_name)
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user