Don't crash if the app icons are wrong

This commit is contained in:
Daniel Martí 2014-01-14 10:28:13 +01:00
parent 607736f85d
commit a7f259e7cc

View file

@ -296,7 +296,7 @@ def resize_icon(iconpath, density):
print iconpath, "is small enough:", im.size print iconpath, "is small enough:", im.size
except Exception,e: except Exception,e:
print "ERROR: Failed resizing {0} - {1}".format(iconpath, e) print "WARNING: Failed resizing {0} - {1}".format(iconpath, e)
def resize_all_icons(repodirs): def resize_all_icons(repodirs):
"""Resize all icons that exceed the max size """Resize all icons that exceed the max size
@ -496,17 +496,20 @@ def scan_apks(apps, apkcache, repodir, knownapks):
iconfile = open(iconpath, 'wb') iconfile = open(iconpath, 'wb')
iconfile.write(apk.read(iconsrc)) iconfile.write(apk.read(iconsrc))
iconfile.close() iconfile.close()
im = Image.open(iconpath) try:
dpi = px_to_dpi(im.size[0]) im = Image.open(iconpath)
for density in densities: dpi = px_to_dpi(im.size[0])
if density in thisinfo['icons']: for density in densities:
break if density in thisinfo['icons']:
if density == densities[-1] or dpi >= int(density): break
thisinfo['icons'][density] = iconfilename if density == densities[-1] or dpi >= int(density):
shutil.move(iconpath, thisinfo['icons'][density] = iconfilename
os.path.join(get_icon_dir(repodir, density), iconfilename)) shutil.move(iconpath,
empty_densities.remove(density) os.path.join(get_icon_dir(repodir, density), iconfilename))
break empty_densities.remove(density)
break
except Exception,e:
print "WARNING: Failed reading {0} - {1}".format(iconpath, e)
if thisinfo['icons']: if thisinfo['icons']:
thisinfo['icon'] = iconfilename thisinfo['icon'] = iconfilename