1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-04 22:40:12 +01:00

metadata: refactor _builds_to_yaml to use dicts and _format functions

_builds_to_yaml does not use any features of the metadata.Build class, so
it can operate on plain dicts as well.  It also does not need to output
Build instances because those are converted to plain dicts when writing out
to YAML.
This commit is contained in:
Hans-Christoph Steiner 2023-05-24 18:43:48 +02:00 committed by Michael Pöhn
parent b055559df7
commit 689786eea4

View File

@ -1157,22 +1157,31 @@ def _del_duplicated_NoSourceSince(app):
def _builds_to_yaml(app): def _builds_to_yaml(app):
"""Reformat Builds: flags for output to YAML 1.2.
This will strip any flag/value that is not set or is empty.
TYPE_BOOL fields are removed when they are false. 0 is valid
value, it should not be stripped, so there are special cases to
handle that.
"""
builds = ruamel.yaml.comments.CommentedSeq() builds = ruamel.yaml.comments.CommentedSeq()
for build in app.get('Builds', []): for build in app.get('Builds', []):
if not isinstance(build, Build):
build = Build(build)
b = ruamel.yaml.comments.CommentedMap() b = ruamel.yaml.comments.CommentedMap()
for field in build_flags: for field in build_flags:
if hasattr(build, field): v = build.get(field)
value = getattr(build, field) if v is None or v is False or v == '' or v == dict() or v == list():
typ = flagtype(field) continue
# don't check value == True for TYPE_INT as it could be 0 _flagtype = flagtype(field)
if value and typ == TYPE_STRINGMAP: if _flagtype == TYPE_MULTILINE:
v = _format_stringmap(app['id'], field, value, build['versionCode']) v = _format_multiline(v)
if v: elif _flagtype == TYPE_SCRIPT:
v = _format_script(v)
elif _flagtype == TYPE_STRINGMAP:
v = _format_stringmap(app['id'], field, v, build['versionCode'])
if v or v == 0:
b[field] = v b[field] = v
elif value is not None and (typ == TYPE_INT or value):
b[field] = value
builds.append(b) builds.append(b)