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:
parent
e6b499a56b
commit
6a875a1821
@ -1423,7 +1423,7 @@ def _get_apk_icons_src(apkfile, icon_name):
|
||||
|
||||
"""
|
||||
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:
|
||||
for filename in zf.namelist():
|
||||
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))
|
||||
|
||||
# extract icons from APK zip file
|
||||
iconfilename = "%s.%s" % (apk['packageName'], apk['versionCode'])
|
||||
iconfilename = "%s.%s.png" % (apk['packageName'], apk['versionCode'])
|
||||
try:
|
||||
empty_densities = extract_apk_icons(iconfilename, apk, apkzip, repodir)
|
||||
finally:
|
||||
@ -1773,8 +1773,6 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
|
||||
if m and m.group(4) == 'png':
|
||||
density = screen_resolutions[m.group(2)]
|
||||
pngs[m.group(3) + '/' + density] = m.group(0)
|
||||
|
||||
icon_type = None
|
||||
empty_densities = []
|
||||
for density in screen_densities:
|
||||
if density not in apk['icons_src']:
|
||||
@ -1782,7 +1780,7 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
|
||||
continue
|
||||
icon_src = apk['icons_src'][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
|
||||
if icon_src.endswith('.xml'):
|
||||
@ -1793,26 +1791,22 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
|
||||
icon_src = name
|
||||
if icon_src.endswith('.xml'):
|
||||
empty_densities.append(density)
|
||||
icon_type = '.xml'
|
||||
icon_dest = os.path.join(icon_dir, icon_filename + icon_type)
|
||||
|
||||
continue
|
||||
try:
|
||||
with open(icon_dest, 'wb') as f:
|
||||
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:
|
||||
logging.warning("Error retrieving icon file: %s %s", icon_dest, e)
|
||||
del apk['icons_src'][density]
|
||||
empty_densities.append(density)
|
||||
|
||||
# '-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_type = icon_src[-4:]
|
||||
icon_path = os.path.join(get_icon_dir(repo_dir, '0'), icon_filename + icon_type)
|
||||
icon_path = os.path.join(get_icon_dir(repo_dir, '0'), icon_filename)
|
||||
with open(icon_path, 'wb') as f:
|
||||
f.write(get_icon_bytes(apkzip, icon_src))
|
||||
if icon_type == '.png':
|
||||
im = None
|
||||
try:
|
||||
im = Image.open(icon_path)
|
||||
@ -1821,9 +1815,9 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
|
||||
if density in apk['icons']:
|
||||
break
|
||||
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,
|
||||
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)
|
||||
break
|
||||
except Exception as e:
|
||||
@ -1834,7 +1828,7 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
|
||||
im.close()
|
||||
|
||||
if apk['icons']:
|
||||
apk['icon'] = icon_filename + icon_type
|
||||
apk['icon'] = icon_filename
|
||||
|
||||
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
|
||||
|
||||
"""
|
||||
icon_filename += '.png'
|
||||
# First try resizing down to not lose quality
|
||||
last_density = None
|
||||
for density in screen_densities:
|
||||
|
@ -54,7 +54,6 @@
|
||||
"name": "Caffeine Tile",
|
||||
"summary": "Test app for extracting icons when an XML one is default",
|
||||
"added": 1539129600000,
|
||||
"icon": "info.zwanenburg.caffeinetile.4.xml",
|
||||
"packageName": "info.zwanenburg.caffeinetile",
|
||||
"lastUpdated": 1539129600000
|
||||
},
|
||||
|
@ -53,7 +53,6 @@ Features:
|
||||
<lastupdated>2018-10-10</lastupdated>
|
||||
<name>Caffeine Tile</name>
|
||||
<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>
|
||||
<license>Unknown</license>
|
||||
<categories>Development</categories>
|
||||
|
@ -707,8 +707,7 @@ class UpdateTest(unittest.TestCase):
|
||||
|
||||
apk_info = fdroidserver.update.scan_apk('repo/info.zwanenburg.caffeinetile_4.apk')
|
||||
self.assertEqual(apk_info.get('versionName'), '1.3')
|
||||
self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable/ic_coffee_on.xml',
|
||||
'-1': 'res/drawable/ic_coffee_on.xml'})
|
||||
self.assertEqual(apk_info['icons_src'], {})
|
||||
|
||||
apk_info = fdroidserver.update.scan_apk('repo/com.politedroid_6.apk')
|
||||
self.assertEqual(apk_info.get('versionName'), '1.5')
|
||||
|
Loading…
Reference in New Issue
Block a user