mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-15 03:30:29 +03:00
rewritemeta: split into remove_blank_flags_from_builds()
This takes this key bit of functionality, splits it out as its own function, and adds some unit tests.
This commit is contained in:
parent
8ccc89ad4e
commit
f9864dc3a2
2 changed files with 138 additions and 13 deletions
|
|
@ -44,6 +44,22 @@ def proper_format(app):
|
|||
return content == cur_content
|
||||
|
||||
|
||||
def remove_blank_flags_from_builds(builds):
|
||||
"""Remove unset entries from Builds so they are not written out."""
|
||||
if not builds:
|
||||
return list()
|
||||
newbuilds = list()
|
||||
for build in builds:
|
||||
new = dict()
|
||||
for k in metadata.build_flags:
|
||||
v = build[k]
|
||||
if v is None or v is False or v == [] or v == '':
|
||||
continue
|
||||
new[k] = v
|
||||
newbuilds.append(new)
|
||||
return newbuilds
|
||||
|
||||
|
||||
def main():
|
||||
global config, options
|
||||
|
||||
|
|
@ -82,16 +98,9 @@ def main():
|
|||
print(path)
|
||||
continue
|
||||
|
||||
newbuilds = []
|
||||
for build in app.get('Builds', []):
|
||||
new = metadata.Build()
|
||||
for k in metadata.build_flags:
|
||||
v = build[k]
|
||||
if v is None or v is False or v == [] or v == '':
|
||||
continue
|
||||
new[k] = v
|
||||
newbuilds.append(new)
|
||||
app['Builds'] = newbuilds
|
||||
builds = remove_blank_flags_from_builds(app.get('Builds'))
|
||||
if builds:
|
||||
app['Builds'] = builds
|
||||
|
||||
# rewrite to temporary file before overwriting existing
|
||||
# file in case there's a bug in write_metadata
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue