mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
DRYer
This commit is contained in:
parent
ef39992968
commit
d79cfbca8f
@ -244,8 +244,7 @@ def icon(ctx, rd, which):
|
|||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
raise HTTPNotFound()
|
raise HTTPNotFound()
|
||||||
with lock:
|
with lock:
|
||||||
tdir = os.path.join(rd.tdir, 'icons')
|
cached = os.path.join(rd.tdir, 'icons', '%d-%s.png' % (sz, which))
|
||||||
cached = os.path.join(tdir, '%d-%s.png' % (sz, which))
|
|
||||||
try:
|
try:
|
||||||
return share_open(cached, 'rb')
|
return share_open(cached, 'rb')
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
@ -260,14 +259,7 @@ def icon(ctx, rd, which):
|
|||||||
scaled, width, height = fit_image(img.width(), img.height(), sz, sz)
|
scaled, width, height = fit_image(img.width(), img.height(), sz, sz)
|
||||||
if scaled:
|
if scaled:
|
||||||
idata = scale_image(img, width, height, as_png=True)[-1]
|
idata = scale_image(img, width, height, as_png=True)[-1]
|
||||||
try:
|
ans = open_for_write(cached)
|
||||||
ans = share_open(cached, 'w+b')
|
|
||||||
except EnvironmentError:
|
|
||||||
try:
|
|
||||||
os.mkdir(tdir)
|
|
||||||
except EnvironmentError:
|
|
||||||
pass
|
|
||||||
ans = share_open(cached, 'w+b')
|
|
||||||
ans.write(idata)
|
ans.write(idata)
|
||||||
ans.seek(0)
|
ans.seek(0)
|
||||||
return ans
|
return ans
|
||||||
|
Loading…
x
Reference in New Issue
Block a user