1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-19 21:30:10 +01:00

update: stop extracting and storing XML icons, they're useless

APKs that only have XML icons in them should include an icon.png in the
metadata or fastlane/triple-t

closes #344
This commit is contained in:
Hans-Christoph Steiner 2018-02-14 13:44:58 +01:00
parent e6b499a56b
commit 6a875a1821
4 changed files with 28 additions and 38 deletions

View File

@ -1423,7 +1423,7 @@ def _get_apk_icons_src(apkfile, icon_name):
""" """
icons_src = dict() icons_src = dict()
density_re = re.compile(r'^res/(.*)/{}\.(png|xml)$'.format(icon_name)) density_re = re.compile(r'^res/(.*)/{}\.png$'.format(icon_name))
with zipfile.ZipFile(apkfile) as zf: with zipfile.ZipFile(apkfile) as zf:
for filename in zf.namelist(): for filename in zf.namelist():
m = density_re.match(filename) m = density_re.match(filename)
@ -1686,7 +1686,7 @@ def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=Fal
.format(apkfilename=apkfile) + str(e)) .format(apkfilename=apkfile) + str(e))
# extract icons from APK zip file # extract icons from APK zip file
iconfilename = "%s.%s" % (apk['packageName'], apk['versionCode']) iconfilename = "%s.%s.png" % (apk['packageName'], apk['versionCode'])
try: try:
empty_densities = extract_apk_icons(iconfilename, apk, apkzip, repodir) empty_densities = extract_apk_icons(iconfilename, apk, apkzip, repodir)
finally: finally:
@ -1773,8 +1773,6 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
if m and m.group(4) == 'png': if m and m.group(4) == 'png':
density = screen_resolutions[m.group(2)] density = screen_resolutions[m.group(2)]
pngs[m.group(3) + '/' + density] = m.group(0) pngs[m.group(3) + '/' + density] = m.group(0)
icon_type = None
empty_densities = [] empty_densities = []
for density in screen_densities: for density in screen_densities:
if density not in apk['icons_src']: if density not in apk['icons_src']:
@ -1782,7 +1780,7 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
continue continue
icon_src = apk['icons_src'][density] icon_src = apk['icons_src'][density]
icon_dir = get_icon_dir(repo_dir, density) icon_dir = get_icon_dir(repo_dir, density)
icon_type = '.png' icon_dest = os.path.join(icon_dir, icon_filename)
# Extract the icon files per density # Extract the icon files per density
if icon_src.endswith('.xml'): if icon_src.endswith('.xml'):
@ -1793,26 +1791,22 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
icon_src = name icon_src = name
if icon_src.endswith('.xml'): if icon_src.endswith('.xml'):
empty_densities.append(density) empty_densities.append(density)
icon_type = '.xml' continue
icon_dest = os.path.join(icon_dir, icon_filename + icon_type)
try: try:
with open(icon_dest, 'wb') as f: with open(icon_dest, 'wb') as f:
f.write(get_icon_bytes(apkzip, icon_src)) f.write(get_icon_bytes(apkzip, icon_src))
apk['icons'][density] = icon_filename + icon_type apk['icons'][density] = icon_filename
except (zipfile.BadZipFile, ValueError, KeyError) as e: except (zipfile.BadZipFile, ValueError, KeyError) as e:
logging.warning("Error retrieving icon file: %s %s", icon_dest, e) logging.warning("Error retrieving icon file: %s %s", icon_dest, e)
del apk['icons_src'][density] del apk['icons_src'][density]
empty_densities.append(density) empty_densities.append(density)
# '-1' here is a remnant of the parsing of aapt output, meaning "no DPI specified" # '-1' here is a remnant of the parsing of aapt output, meaning "no DPI specified"
if '-1' in apk['icons_src']: if '-1' in apk['icons_src'] and not apk['icons_src']['-1'].endswith('.xml'):
icon_src = apk['icons_src']['-1'] icon_src = apk['icons_src']['-1']
icon_type = icon_src[-4:] icon_path = os.path.join(get_icon_dir(repo_dir, '0'), icon_filename)
icon_path = os.path.join(get_icon_dir(repo_dir, '0'), icon_filename + icon_type)
with open(icon_path, 'wb') as f: with open(icon_path, 'wb') as f:
f.write(get_icon_bytes(apkzip, icon_src)) f.write(get_icon_bytes(apkzip, icon_src))
if icon_type == '.png':
im = None im = None
try: try:
im = Image.open(icon_path) im = Image.open(icon_path)
@ -1821,9 +1815,9 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
if density in apk['icons']: if density in apk['icons']:
break break
if density == screen_densities[-1] or dpi >= int(density): if density == screen_densities[-1] or dpi >= int(density):
apk['icons'][density] = icon_filename + icon_type apk['icons'][density] = icon_filename
shutil.move(icon_path, shutil.move(icon_path,
os.path.join(get_icon_dir(repo_dir, density), icon_filename + icon_type)) os.path.join(get_icon_dir(repo_dir, density), icon_filename))
empty_densities.remove(density) empty_densities.remove(density)
break break
except Exception as e: except Exception as e:
@ -1834,7 +1828,7 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
im.close() im.close()
if apk['icons']: if apk['icons']:
apk['icon'] = icon_filename + icon_type apk['icon'] = icon_filename
return empty_densities return empty_densities
@ -1849,7 +1843,6 @@ def fill_missing_icon_densities(empty_densities, icon_filename, apk, repo_dir):
:param repo_dir: The directory of the APK's repository :param repo_dir: The directory of the APK's repository
""" """
icon_filename += '.png'
# First try resizing down to not lose quality # First try resizing down to not lose quality
last_density = None last_density = None
for density in screen_densities: for density in screen_densities:

View File

@ -54,7 +54,6 @@
"name": "Caffeine Tile", "name": "Caffeine Tile",
"summary": "Test app for extracting icons when an XML one is default", "summary": "Test app for extracting icons when an XML one is default",
"added": 1539129600000, "added": 1539129600000,
"icon": "info.zwanenburg.caffeinetile.4.xml",
"packageName": "info.zwanenburg.caffeinetile", "packageName": "info.zwanenburg.caffeinetile",
"lastUpdated": 1539129600000 "lastUpdated": 1539129600000
}, },

View File

@ -53,7 +53,6 @@ Features:
<lastupdated>2018-10-10</lastupdated> <lastupdated>2018-10-10</lastupdated>
<name>Caffeine Tile</name> <name>Caffeine Tile</name>
<summary>Test app for extracting icons when an XML one is default</summary> <summary>Test app for extracting icons when an XML one is default</summary>
<icon>info.zwanenburg.caffeinetile.4.xml</icon>
<desc>No description available</desc> <desc>No description available</desc>
<license>Unknown</license> <license>Unknown</license>
<categories>Development</categories> <categories>Development</categories>

View File

@ -707,8 +707,7 @@ class UpdateTest(unittest.TestCase):
apk_info = fdroidserver.update.scan_apk('repo/info.zwanenburg.caffeinetile_4.apk') apk_info = fdroidserver.update.scan_apk('repo/info.zwanenburg.caffeinetile_4.apk')
self.assertEqual(apk_info.get('versionName'), '1.3') self.assertEqual(apk_info.get('versionName'), '1.3')
self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable/ic_coffee_on.xml', self.assertEqual(apk_info['icons_src'], {})
'-1': 'res/drawable/ic_coffee_on.xml'})
apk_info = fdroidserver.update.scan_apk('repo/com.politedroid_6.apk') apk_info = fdroidserver.update.scan_apk('repo/com.politedroid_6.apk')
self.assertEqual(apk_info.get('versionName'), '1.5') self.assertEqual(apk_info.get('versionName'), '1.5')