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.
This commit is contained in:
Hans-Christoph Steiner 2020-11-13 11:19:24 +01:00
parent e93acf7964
commit 0b879f18e5
2 changed files with 9 additions and 9 deletions

View file

@ -358,7 +358,7 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
for appid, appdict in apps.items(): for appid, appdict in apps.items():
app = metadata.App(appdict) app = metadata.App(appdict)
if app.Disabled is not None: if app.get('Disabled') is not None:
continue continue
# Get a list of the apks for this app... # Get a list of the apks for this app...

View file

@ -247,13 +247,13 @@ def update_wiki(apps, apks):
buildfails = False buildfails = False
for apk in apks: for apk in apks:
if apk['packageName'] == appid: if apk['packageName'] == appid:
if str(apk['versionCode']) == app.CurrentVersionCode: if str(apk['versionCode']) == app.get('CurrentVersionCode'):
gotcurrentver = True gotcurrentver = True
apklist.append(apk) apklist.append(apk)
# Include ones we can't build, as a special case... # Include ones we can't build, as a special case...
for build in app.get('Builds', []): for build in app.get('Builds', []):
if build.disable: if build.disable:
if build.versionCode == app.CurrentVersionCode: if build.versionCode == app.get('CurrentVersionCode'):
cantupdate = True cantupdate = True
# TODO: Nasty: vercode is a string in the build, and an int elsewhere # TODO: Nasty: vercode is a string in the build, and an int elsewhere
apklist.append({'versionCode': int(build.versionCode), apklist.append({'versionCode': int(build.versionCode),
@ -272,7 +272,7 @@ def update_wiki(apps, apks):
'versionName': build.versionName, 'versionName': build.versionName,
'buildproblem': "The build for this version appears to have failed. Check the [[{0}/lastbuild_{1}|build log]].".format(appid, build.versionCode), '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 cantupdate = True
# Sort with most recent first... # Sort with most recent first...
apklist = sorted(apklist, key=lambda apk: apk['versionCode'], reverse=True) 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: if app.get('Name') is None:
app['Name'] = bestapk['name'] 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['CurrentVersionCode'] is None: if app.get('CurrentVersionCode') is None:
app['CurrentVersionCode'] = str(bestver) app['CurrentVersionCode'] = str(bestver)
@ -1931,8 +1931,8 @@ def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversi
currentVersionApk = None currentVersionApk = None
for apk in apk_list: for apk in apk_list:
if apk['packageName'] == appid: if apk['packageName'] == appid:
if app.CurrentVersionCode is not None: if app.get('CurrentVersionCode') is not None:
if apk['versionCode'] == common.version_code_string_to_int(app.CurrentVersionCode): if apk['versionCode'] == common.version_code_string_to_int(app['CurrentVersionCode']):
currentVersionApk = apk currentVersionApk = apk
continue continue
apkList.append(apk) apkList.append(apk)
@ -1946,8 +1946,8 @@ def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversi
for appid, app in apps.items(): for appid, app in apps.items():
if app.ArchivePolicy: if app.get('ArchivePolicy'):
keepversions = int(app.ArchivePolicy[:-9]) keepversions = int(app['ArchivePolicy'][:-9])
else: else:
keepversions = defaultkeepversions keepversions = defaultkeepversions