mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-10-08 18:31:07 +03:00
properly close opened images
This stops these errors: fdroid/fdroidserver/fdroidserver/update.py:744: ResourceWarning: unclosed file <_io.BufferedReader name='repo/icons-320/info.guardianproject.urzip.100.png'> fdroid/fdroidserver/fdroidserver/update.py:721: DeprecationWarning: The 'warn' function is deprecated, use 'warning' instead
This commit is contained in:
parent
1210dc7769
commit
d6c9a8466b
1 changed files with 21 additions and 11 deletions
|
@ -323,8 +323,10 @@ def resize_icon(iconpath, density):
|
|||
if not os.path.isfile(iconpath):
|
||||
return
|
||||
|
||||
fp = None
|
||||
try:
|
||||
im = Image.open(iconpath)
|
||||
fp = open(iconpath, 'rb')
|
||||
im = Image.open(fp)
|
||||
size = dpi_to_px(density)
|
||||
|
||||
if any(length > size for length in im.size):
|
||||
|
@ -337,6 +339,10 @@ def resize_icon(iconpath, density):
|
|||
except Exception as e:
|
||||
logging.error("Failed resizing {0} - {1}".format(iconpath, e))
|
||||
|
||||
finally:
|
||||
if fp:
|
||||
fp.close()
|
||||
|
||||
|
||||
def resize_all_icons(repodirs):
|
||||
"""Resize all icons that exceed the max size
|
||||
|
@ -563,7 +569,7 @@ def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False):
|
|||
|
||||
# Check for debuggable apks...
|
||||
if common.isApkDebuggable(apkfile, config):
|
||||
logging.warn('{0} is set to android:debuggable="true"'.format(apkfile))
|
||||
logging.warning('{0} is set to android:debuggable="true"'.format(apkfile))
|
||||
|
||||
# Get the signature (or md5 of, to be precise)...
|
||||
logging.debug('Getting signature of {0}'.format(apkfile))
|
||||
|
@ -657,17 +663,21 @@ def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False):
|
|||
get_icon_dir(repodir, last_density), iconfilename)
|
||||
iconpath = os.path.join(
|
||||
get_icon_dir(repodir, density), iconfilename)
|
||||
fp = None
|
||||
try:
|
||||
im = Image.open(last_iconpath)
|
||||
except:
|
||||
logging.warn("Invalid image file at %s" % last_iconpath)
|
||||
continue
|
||||
fp = open(last_iconpath, 'rb')
|
||||
im = Image.open(fp)
|
||||
|
||||
size = dpi_to_px(density)
|
||||
|
||||
im.thumbnail((size, size), Image.ANTIALIAS)
|
||||
im.save(iconpath, "PNG")
|
||||
empty_densities.remove(density)
|
||||
except:
|
||||
logging.warning("Invalid image file at %s" % last_iconpath)
|
||||
finally:
|
||||
if fp:
|
||||
fp.close()
|
||||
|
||||
# Then just copy from the highest resolution available
|
||||
last_density = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue