1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-19 21:30:10 +01:00

metadata: simplify _app_to_yaml()

There are some redundant checks and odd construct:
* cm.update({a: b}) --> cm[a] = b
* getattr(app, field) --> app.get(field)
This commit is contained in:
Hans-Christoph Steiner 2023-05-08 14:44:01 +02:00
parent 2cb12f9594
commit e8ab84b583

View File

@ -1100,22 +1100,21 @@ def _app_to_yaml(app):
# next iteration will need to insert a newline # next iteration will need to insert a newline
insert_newline = True insert_newline = True
else: else:
if app.get(field) or field == 'Builds': value = app.get(field)
if value or field == 'Builds':
if field == 'Builds': if field == 'Builds':
if app.get('Builds'): if app.get('Builds'):
cm.update({field: _builds_to_yaml(app)}) cm.update({field: _builds_to_yaml(app)})
elif field == 'CurrentVersionCode': elif field == 'CurrentVersionCode':
cm.update({field: _field_to_yaml(TYPE_INT, getattr(app, field))}) cm[field] = _field_to_yaml(TYPE_INT, value)
elif field == 'AllowedAPKSigningKeys': elif field == 'AllowedAPKSigningKeys':
value = getattr(app, field)
if value:
value = [str(i).lower() for i in value] value = [str(i).lower() for i in value]
if len(value) == 1: if len(value) == 1:
cm.update({field: _field_to_yaml(TYPE_STRING, value[0])}) cm[field] = _field_to_yaml(TYPE_STRING, value[0])
else: else:
cm.update({field: _field_to_yaml(TYPE_LIST, value)}) cm[field] = _field_to_yaml(TYPE_LIST, value)
else: else:
cm.update({field: _field_to_yaml(fieldtype(field), getattr(app, field))}) cm[field] = _field_to_yaml(fieldtype(field), value)
if insert_newline: if insert_newline:
# we need to prepend a newline in front of this field # we need to prepend a newline in front of this field