only use AutoName: in checkupdates

AutoName: is only needed for the commit messages generated by checkupdates,
and it makes the logic for localized names confusing.

closes #654
refs #304
This commit is contained in:
Hans-Christoph Steiner 2020-01-13 15:43:42 +01:00
parent 0f6b638986
commit fff59e5197
11 changed files with 289 additions and 49 deletions

View file

@ -3511,9 +3511,9 @@ def get_certificate(signature_block_file):
def load_stats_fdroid_signing_key_fingerprints():
"""Load list of signing-key fingerprints stored by fdroid publish from file.
"""Load signing-key fingerprints stored in file generated by fdroid publish.
:returns: list of dictionanryies containing the singing-key fingerprints.
:returns: dict containing the signing-key fingerprints.
"""
jar_file = os.path.join('stats', 'publishsigkeys.jar')
if not os.path.isfile(jar_file):

View file

@ -159,7 +159,7 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
if not v:
continue
if k in ('Builds', 'comments', 'metadatapath',
'ArchivePolicy', 'AutoUpdateMode', 'MaintainerNotes',
'ArchivePolicy', 'AutoName', 'AutoUpdateMode', 'MaintainerNotes',
'Provides', 'Repo', 'RepoType', 'RequiresRoot',
'UpdateCheckData', 'UpdateCheckIgnore', 'UpdateCheckMode',
'UpdateCheckName', 'NoSourceSince', 'VercodeOperation'):
@ -172,10 +172,6 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
k = 'suggestedVersionCode'
elif k == 'CurrentVersion': # TODO make SuggestedVersionName the canonical name
k = 'suggestedVersionName'
elif k == 'AutoName':
if 'Name' not in apps[packageName]:
d['name'] = v
continue
else:
k = k[:1].lower() + k[1:]
d[k] = v
@ -326,6 +322,8 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
value = localized[lang].get(lkey)
if not value:
value = default
if not value and name == 'name' and app.get('AutoName'):
value = app['AutoName']
el.appendChild(doc.createTextNode(value))
parent.appendChild(el)
@ -363,10 +361,13 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
# Get a list of the apks for this app...
apklist = []
name_from_apk = None
apksbyversion = collections.defaultdict(lambda: [])
for apk in apks:
if apk.get('versionCode') and apk.get('packageName') == appid:
apksbyversion[apk['versionCode']].append(apk)
if name_from_apk is None:
name_from_apk = apk.get('name')
for versionCode, apksforver in apksbyversion.items():
fdroidsig = fdroid_signing_key_fingerprints.get(appid, {}).get('signer')
fdroid_signed_apk = None
@ -398,7 +399,7 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
if app.lastUpdated:
addElement('lastupdated', app.lastUpdated.strftime('%Y-%m-%d'), doc, apel)
addElementCheckLocalized('name', app, 'Name', doc, apel)
addElementCheckLocalized('name', app, 'Name', doc, apel, name_from_apk)
addElementCheckLocalized('summary', app, 'Summary', doc, apel)
if app.icon:
@ -543,7 +544,12 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
and common.config['make_current_version_link'] \
and repodir == 'repo': # only create these
namefield = common.config['current_version_name_source']
sanitized_name = re.sub(b'''[ '"&%?+=/]''', b'', app.get(namefield).encode('utf-8'))
name = app.get(namefield)
if not name and namefield == 'Name':
name = app.get('localized', {}).get('en-US', {}).get('name')
if not name:
name = app.id
sanitized_name = re.sub(b'''[ '"&%?+=/]''', b'', name.encode('utf-8'))
apklinkname = sanitized_name + os.path.splitext(current_version_file)[1].encode('utf-8')
current_version_path = os.path.join(repodir, current_version_file).encode('utf-8', 'surrogateescape')
if os.path.islink(apklinkname):

View file

@ -323,9 +323,6 @@ def check_categories(app):
def check_duplicates(app):
if app.Name and app.Name == app.AutoName:
yield _("Name '%s' is just the auto name - remove it") % app.Name
links_seen = set()
for f in ['Source Code', 'Web Site', 'Issue Tracker', 'Changelog']:
v = app.get(f)

View file

@ -1905,15 +1905,10 @@ def apply_info_from_latest_apk(apps, apks):
logging.debug("Don't know when " + appid + " was last updated")
if bestver == UNSET_VERSION_CODE:
if app.get('Name') is None:
app['Name'] = app['AutoName'] or appid
app['icon'] = None
logging.debug("Application " + appid + " has no packages")
else:
if app.get('Name') is None:
app['Name'] = bestapk['name']
app['icon'] = bestapk['icon'] if 'icon' in bestapk else None
app.icon = bestapk['icon'] if 'icon' in bestapk else None
if app.get('CurrentVersionCode') is None:
app['CurrentVersionCode'] = str(bestver)
@ -2106,23 +2101,45 @@ def read_added_date_from_all_apks(apps, apks):
app['lastUpdated'] = apk['added']
def read_names_from_apks(apps, apks):
"""This is a stripped down copy of apply_info_from_latest_apk that only parses app names"""
def insert_missing_app_names_from_apks(apps, apks):
"""Use app name from APK if it is not set in the metadata
Name -> localized -> from APK
The name from the APK is set as the default name for the app if
there is no other default set, e.g. app['Name'] or
app['localized']['en-US']['name']. The en-US locale is defined in
the F-Droid ecosystem as the locale of last resort, as in the one
that should always be present. en-US is used since it is the
locale of the source strings.
This should only be used for index v0 and v1. Later versions of
the index should be sorted by Application ID, since it is
guaranteed to always be there. Before, the index was stored by
the app name (aka <application android:label="">) to save the
website from having to sort the entries. That is no longer
relevant since the website switched from Wordpress to Jekyll.
"""
for appid, app in apps.items():
if app.get('Name') is not None:
continue
if app.get('localized', {}).get('en-US', {}).get('name') is not None:
continue
bestver = UNSET_VERSION_CODE
for apk in apks:
if apk['packageName'] == appid:
if apk['versionCode'] > bestver:
if apk.get('name') and apk['versionCode'] > bestver:
bestver = apk['versionCode']
bestapk = apk
if bestver == UNSET_VERSION_CODE:
if app.Name is None:
app.Name = common.get_app_display_name(app)
app.icon = None
else:
if app.Name is None:
app.Name = bestapk['name']
if bestver != UNSET_VERSION_CODE:
if 'localized' not in app:
app['localized'] = {}
if 'en-US' not in app['localized']:
app['localized']['en-US'] = {}
app['localized']['en-US']['name'] = bestapk.get('name')
def get_apps_with_packages(apps, apks):
@ -2161,6 +2178,7 @@ def prepare_apps(apps, apks, repodir):
translate_per_build_anti_features(apps_with_packages, apks)
if repodir == 'repo':
insert_localized_app_metadata(apps_with_packages)
insert_missing_app_names_from_apks(apps_with_packages, apks)
return apps_with_packages
@ -2307,12 +2325,6 @@ def main():
else:
archapks = []
# We need app.Name populated for all apps regardless of which repo they end up in
# for the old-style inter-app links, so let's do it before we do anything else.
# This will be done again (as part of apply_info_from_latest_apk) for repo and archive
# separately later on, but it's fairly cheap anyway.
read_names_from_apks(apps, apks + archapks)
if cachechanged:
write_cache(apkcache)