mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #8451: Error Communicating with Device when sending covers.
This commit is contained in:
parent
35c319f115
commit
e008ff22b7
@ -201,10 +201,13 @@ class PRS505(USBMS):
|
|||||||
self._card_b_prefix if idx == 2 \
|
self._card_b_prefix if idx == 2 \
|
||||||
else self._main_prefix
|
else self._main_prefix
|
||||||
for book in bl:
|
for book in bl:
|
||||||
p = os.path.join(prefix, book.lpath)
|
try:
|
||||||
self._upload_cover(os.path.dirname(p),
|
p = os.path.join(prefix, book.lpath)
|
||||||
os.path.splitext(os.path.basename(p))[0],
|
self._upload_cover(os.path.dirname(p),
|
||||||
book, p)
|
os.path.splitext(os.path.basename(p))[0],
|
||||||
|
book, p)
|
||||||
|
except:
|
||||||
|
debug_print('FAILED to upload cover', p)
|
||||||
else:
|
else:
|
||||||
debug_print('PRS505: NOT uploading covers in sync_booklists')
|
debug_print('PRS505: NOT uploading covers in sync_booklists')
|
||||||
|
|
||||||
@ -222,6 +225,12 @@ class PRS505(USBMS):
|
|||||||
self.plugboards = plugboards
|
self.plugboards = plugboards
|
||||||
self.plugboard_func = pb_func
|
self.plugboard_func = pb_func
|
||||||
|
|
||||||
|
def create_upload_path(self, path, mdata, fname, create_dirs=True):
|
||||||
|
maxlen = 250 - (max(len(CACHE_THUMBNAIL), len(MEDIA_THUMBNAIL)) +
|
||||||
|
len('main_thumbnail.jpg') + 1)
|
||||||
|
return self._create_upload_path(path, mdata, fname,
|
||||||
|
create_dirs=create_dirs, maxlen=maxlen)
|
||||||
|
|
||||||
def upload_cover(self, path, filename, metadata, filepath):
|
def upload_cover(self, path, filename, metadata, filepath):
|
||||||
opts = self.settings()
|
opts = self.settings()
|
||||||
if not opts.extra_customization[self.OPT_UPLOAD_COVERS]:
|
if not opts.extra_customization[self.OPT_UPLOAD_COVERS]:
|
||||||
|
@ -874,8 +874,12 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
def create_upload_path(self, path, mdata, fname, create_dirs=True):
|
def create_upload_path(self, path, mdata, fname, create_dirs=True):
|
||||||
|
return self._create_upload_path(path, mdata, fname,
|
||||||
|
create_dirs=create_dirs, maxlen=250)
|
||||||
|
|
||||||
|
def _create_upload_path(self, path, mdata, fname, create_dirs=True,
|
||||||
|
maxlen=None):
|
||||||
path = os.path.abspath(path)
|
path = os.path.abspath(path)
|
||||||
extra_components = []
|
|
||||||
|
|
||||||
special_tag = None
|
special_tag = None
|
||||||
if mdata.tags:
|
if mdata.tags:
|
||||||
@ -902,7 +906,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
app_id = str(getattr(mdata, 'application_id', ''))
|
app_id = str(getattr(mdata, 'application_id', ''))
|
||||||
# The db id will be in the created filename
|
# The db id will be in the created filename
|
||||||
extra_components = get_components(template, mdata, fname,
|
extra_components = get_components(template, mdata, fname,
|
||||||
timefmt=opts.send_timefmt, length=250-len(app_id)-1)
|
timefmt=opts.send_timefmt, length=maxlen-len(app_id)-1)
|
||||||
if not extra_components:
|
if not extra_components:
|
||||||
extra_components.append(sanitize(self.filename_callback(fname,
|
extra_components.append(sanitize(self.filename_callback(fname,
|
||||||
mdata)))
|
mdata)))
|
||||||
@ -937,12 +941,11 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
extra_components = list(map(remove_trailing_periods, extra_components))
|
extra_components = list(map(remove_trailing_periods, extra_components))
|
||||||
components = shorten_components_to(250 - len(path), extra_components)
|
components = shorten_components_to(maxlen - len(path), extra_components)
|
||||||
components = self.sanitize_path_components(components)
|
components = self.sanitize_path_components(components)
|
||||||
filepath = os.path.join(path, *components)
|
filepath = os.path.join(path, *components)
|
||||||
filedir = os.path.dirname(filepath)
|
filedir = os.path.dirname(filepath)
|
||||||
|
|
||||||
|
|
||||||
if create_dirs and not os.path.exists(filedir):
|
if create_dirs and not os.path.exists(filedir):
|
||||||
os.makedirs(filedir)
|
os.makedirs(filedir)
|
||||||
|
|
||||||
|
@ -42,30 +42,44 @@ def supports_long_names(path):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def shorten_components_to(length, components):
|
def shorten_component(s, byWhat):
|
||||||
|
l = len(s)
|
||||||
|
if l < byWhat:
|
||||||
|
return s
|
||||||
|
l = int((l-byWhat)/2)
|
||||||
|
if l <= 0:
|
||||||
|
return s
|
||||||
|
return s[0:l] + s[-l:]
|
||||||
|
|
||||||
|
def shorten_components_to(length, components, more_to_take = 0):
|
||||||
filepath = os.sep.join(components)
|
filepath = os.sep.join(components)
|
||||||
extra = len(filepath) - length
|
extra = len(filepath) - (length - more_to_take)
|
||||||
if extra < 1:
|
if extra < 1:
|
||||||
return components
|
return components
|
||||||
delta = int(ceil(extra/float(len(components))))
|
deltas = []
|
||||||
ans = []
|
|
||||||
for x in components:
|
for x in components:
|
||||||
|
pct = len(x)/float(len(filepath))
|
||||||
|
deltas.append(int(ceil(pct*extra)))
|
||||||
|
ans = []
|
||||||
|
|
||||||
|
for i,x in enumerate(components):
|
||||||
|
delta = deltas[i]
|
||||||
if delta > len(x):
|
if delta > len(x):
|
||||||
r = x[0] if x is components[-1] else ''
|
r = x[0] if x is components[-1] else ''
|
||||||
else:
|
else:
|
||||||
if x is components[-1]:
|
if x is components[-1]:
|
||||||
b, e = os.path.splitext(x)
|
b, e = os.path.splitext(x)
|
||||||
if e == '.': e = ''
|
if e == '.': e = ''
|
||||||
r = b[:-delta]+e
|
r = shorten_component(b, delta)+e
|
||||||
if r.startswith('.'): r = x[0]+r
|
if r.startswith('.'): r = x[0]+r
|
||||||
else:
|
else:
|
||||||
r = x[:-delta]
|
r = shorten_component(x, delta)
|
||||||
r = r.strip()
|
r = r.strip()
|
||||||
if not r:
|
if not r:
|
||||||
r = x.strip()[0] if x.strip() else 'x'
|
r = x.strip()[0] if x.strip() else 'x'
|
||||||
ans.append(r)
|
ans.append(r)
|
||||||
if len(os.sep.join(ans)) > length:
|
if len(os.sep.join(ans)) > length:
|
||||||
return shorten_components_to(length, ans)
|
return shorten_components_to(length, components, more_to_take+2)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def find_executable_in_path(name, path=None):
|
def find_executable_in_path(name, path=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user