From 0a953814e21257d4d362af0468d67d749b069b05 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 19 Jul 2017 10:59:05 +0200 Subject: [PATCH] update: always include name/summary/desc in index.xml if available With the new localization support, the name/summary/description in the metadata file becomes the global override. So most apps are not going to have those fields present in their metadata file. This fixes the index.xml generation to fall back to the localized versions of those fields when they are not set in the metadata field. https://forum.f-droid.org/t/what-has-happend-to-osmand --- fdroidserver/index.py | 43 ++++++++++++++++--- .../metadata/info.guardianproject.checkey.txt | 10 ----- .../en-US/description.txt | 1 + .../en-US/summary.txt | 1 + 4 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 tests/metadata/info.guardianproject.checkey/en-US/description.txt create mode 100644 tests/metadata/info.guardianproject.checkey/en-US/summary.txt diff --git a/fdroidserver/index.py b/fdroidserver/index.py index b0de4325..53d2787a 100644 --- a/fdroidserver/index.py +++ b/fdroidserver/index.py @@ -258,6 +258,35 @@ def make_v0(apps, apks, repodir, repodict, requestsdict): el.appendChild(doc.createCDATASection(value)) parent.appendChild(el) + def addElementCheckLocalized(name, app, key, doc, parent, default=''): + '''Fill in field from metadata or localized block + + For name/summary/description, they can come only from the app source, + or from a dir in fdroiddata. They can be entirely missing from the + metadata file if there is localized versions. This will fetch those + from the localized version if its not available in the metadata file. + ''' + + el = doc.createElement(name) + value = app.get(key) + lkey = key[:1].lower() + key[1:] + localized = app.get('localized') + if not value and localized: + for lang in ['en-US'] + [x for x in localized.keys()]: + if not lang.startswith('en'): + continue + if lang in localized: + value = localized[lang].get(lkey) + if value: + break + if not value and localized and len(localized) > 1: + lang = list(localized.keys())[0] + value = localized[lang].get(lkey) + if not value: + value = default + el.appendChild(doc.createTextNode(value)) + parent.appendChild(el) + root = doc.createElement("fdroid") doc.appendChild(root) @@ -312,16 +341,16 @@ def make_v0(apps, apks, repodir, repodict, requestsdict): addElement('added', app.added.strftime('%Y-%m-%d'), doc, apel) if app.lastUpdated: addElement('lastupdated', app.lastUpdated.strftime('%Y-%m-%d'), doc, apel) - addElement('name', app.Name, doc, apel) - addElement('summary', app.Summary, doc, apel) + + addElementCheckLocalized('name', app, 'Name', doc, apel) + addElementCheckLocalized('summary', app, 'Summary', doc, apel) + if app.icon: addElement('icon', app.icon, doc, apel) - if app.get('Description'): - description = app.Description - else: - description = '

No description available

' - addElement('desc', description, doc, apel) + addElementCheckLocalized('desc', app, 'Description', doc, apel, + '

No description available

') + addElement('license', app.License, doc, apel) if app.Categories: addElement('categories', ','.join(app.Categories), doc, apel) diff --git a/tests/metadata/info.guardianproject.checkey.txt b/tests/metadata/info.guardianproject.checkey.txt index eea6c7be..4beeec89 100644 --- a/tests/metadata/info.guardianproject.checkey.txt +++ b/tests/metadata/info.guardianproject.checkey.txt @@ -6,16 +6,6 @@ Issue Tracker:https://dev.guardianproject.info/projects/checkey/issues Bitcoin:1Fi5xUHiAPRKxHvyUGVFGt9extBe8Srdbk Auto Name:Checkey -Summary:Info on local apps -Description: -Checkey is a utility for getting information about the APKs that are installed -on your device. Starting with a list of all of the apps that you have -installed on your device, it will show you the APK signature with a single -touch, and provides links to virustotal.com and androidobservatory.org to -easily access the profiles of that APK. It will also let you export the -signing certificate and generate ApkSignaturePin pin files for use with the -TrustedIntents library. -. Current Version Code:9999999 diff --git a/tests/metadata/info.guardianproject.checkey/en-US/description.txt b/tests/metadata/info.guardianproject.checkey/en-US/description.txt new file mode 100644 index 00000000..568b9491 --- /dev/null +++ b/tests/metadata/info.guardianproject.checkey/en-US/description.txt @@ -0,0 +1 @@ +Checkey is a utility for getting information about the APKs that are installed on your device. Starting with a list of all of the apps that you have installed on your device, it will show you the APK signature with a single touch, and provides links to virustotal.com and androidobservatory.org to easily access the profiles of that APK. It will also let you export the signing certificate and generate ApkSignaturePin pin files for use with the TrustedIntents library. diff --git a/tests/metadata/info.guardianproject.checkey/en-US/summary.txt b/tests/metadata/info.guardianproject.checkey/en-US/summary.txt new file mode 100644 index 00000000..a4642ad1 --- /dev/null +++ b/tests/metadata/info.guardianproject.checkey/en-US/summary.txt @@ -0,0 +1 @@ +Info on local apps