yml metadata write: do not use local functions

This commit is contained in:
Michael Pöhn 2019-03-19 01:01:18 +01:00
parent 881a79fa84
commit 2683b37044
2 changed files with 85 additions and 85 deletions

View file

@ -1115,15 +1115,7 @@ def post_parse_yaml_metadata(yamldata):
build[flag] = ' && '.join(build[flag]) build[flag] = ' && '.join(build[flag])
def write_yaml(mf, app): def _format_yml_field(field, value, typ, width=80, offset=0):
"""Write metadata in yaml format.
:param mf: active file discriptor for writing
:param app: app metadata to written to the yaml file
"""
def format_yml_field(field, value, typ, width=80, offset=0):
# TODO: use CSafeDumper if available
bool_list_hack = ['gradle'] bool_list_hack = ['gradle']
@ -1189,13 +1181,14 @@ def write_yaml(mf, app):
return raw_yml return raw_yml
def format_yml_build_entry(build):
def _format_yml_build_entry(build):
result = [] result = []
for field in build_flags: for field in build_flags:
value = getattr(build, field, None) value = getattr(build, field, None)
if value: if value:
typ = flagtype(field) typ = flagtype(field)
line = format_yml_field(field, value, typ, width=0xffffffff, offset=4) line = _format_yml_field(field, value, typ, width=0xffffffff, offset=4)
if re.match(r'^\s+$', line): if re.match(r'^\s+$', line):
result.append('') result.append('')
else: else:
@ -1203,6 +1196,14 @@ def write_yaml(mf, app):
result[0] = ' - ' + result[0][4:] result[0] = ' - ' + result[0][4:]
return '\n'.join(result) return '\n'.join(result)
def write_yaml(mf, app):
"""Write metadata in yaml format.
:param mf: active file discriptor for writing
:param app: app metadata to written to the yaml file
"""
result = [] result = []
for field in yaml_app_field_order: for field in yaml_app_field_order:
if field == '\n': if field == '\n':
@ -1219,9 +1220,9 @@ def write_yaml(mf, app):
first_build_entry = False first_build_entry = False
else: else:
result.append('') result.append('')
result.append(format_yml_build_entry(build)) result.append(_format_yml_build_entry(build))
if value: if value:
result.append(format_yml_field(field, value, yml_fieldtype(field))) result.append(_format_yml_field(field, value, yml_fieldtype(field)))
mf.write('\n'.join(result)) mf.write('\n'.join(result))

View file

@ -258,7 +258,6 @@ class MetadataTest(unittest.TestCase):
NoSourceSince: 1.0.1""")) NoSourceSince: 1.0.1"""))
def test_rewrite_yaml_fakeotaupdate(self): def test_rewrite_yaml_fakeotaupdate(self):
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir) testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
fdroidserver.common.config = {'accepted_formats': ['txt', 'yml']} fdroidserver.common.config = {'accepted_formats': ['txt', 'yml']}