From 0b879f18e5704be6d5a74444dbfe50eb6acfb450 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 13 Nov 2020 11:19:24 +0100 Subject: [PATCH] use dict syntax for app instances to allow API usage with plain dicts Since metadata files are now YAML, programs should be able to just read in the .yml files, then use them with fdroidserver methods without having to know about the App class. The App class just provides syntactic sugar by allowing dict keys to be accessed as attributes. --- fdroidserver/index.py | 2 +- fdroidserver/update.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fdroidserver/index.py b/fdroidserver/index.py index 565a1c1e..9b2b68c9 100644 --- a/fdroidserver/index.py +++ b/fdroidserver/index.py @@ -358,7 +358,7 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing for appid, appdict in apps.items(): app = metadata.App(appdict) - if app.Disabled is not None: + if app.get('Disabled') is not None: continue # Get a list of the apks for this app... diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 9e79cc8d..ef1310c7 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -247,13 +247,13 @@ def update_wiki(apps, apks): buildfails = False for apk in apks: if apk['packageName'] == appid: - if str(apk['versionCode']) == app.CurrentVersionCode: + if str(apk['versionCode']) == app.get('CurrentVersionCode'): gotcurrentver = True apklist.append(apk) # Include ones we can't build, as a special case... for build in app.get('Builds', []): if build.disable: - if build.versionCode == app.CurrentVersionCode: + if build.versionCode == app.get('CurrentVersionCode'): cantupdate = True # TODO: Nasty: vercode is a string in the build, and an int elsewhere apklist.append({'versionCode': int(build.versionCode), @@ -272,7 +272,7 @@ def update_wiki(apps, apks): 'versionName': build.versionName, 'buildproblem': "The build for this version appears to have failed. Check the [[{0}/lastbuild_{1}|build log]].".format(appid, build.versionCode), }) - if app.CurrentVersionCode == '0': + if app.get('CurrentVersionCode') == '0': cantupdate = True # Sort with most recent first... apklist = sorted(apklist, key=lambda apk: apk['versionCode'], reverse=True) @@ -1912,7 +1912,7 @@ def apply_info_from_latest_apk(apps, apks): if app.get('Name') is None: app['Name'] = bestapk['name'] app['icon'] = bestapk['icon'] if 'icon' in bestapk else None - if app['CurrentVersionCode'] is None: + if app.get('CurrentVersionCode') is None: app['CurrentVersionCode'] = str(bestver) @@ -1931,8 +1931,8 @@ def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversi currentVersionApk = None for apk in apk_list: if apk['packageName'] == appid: - if app.CurrentVersionCode is not None: - if apk['versionCode'] == common.version_code_string_to_int(app.CurrentVersionCode): + if app.get('CurrentVersionCode') is not None: + if apk['versionCode'] == common.version_code_string_to_int(app['CurrentVersionCode']): currentVersionApk = apk continue apkList.append(apk) @@ -1946,8 +1946,8 @@ def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversi for appid, app in apps.items(): - if app.ArchivePolicy: - keepversions = int(app.ArchivePolicy[:-9]) + if app.get('ArchivePolicy'): + keepversions = int(app['ArchivePolicy'][:-9]) else: keepversions = defaultkeepversions