From 31ca2092a19adc3d4b5f302dafb72a4babb882ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Wed, 14 Nov 2018 13:42:05 +0100 Subject: [PATCH] yaml parsing: script build flags can now be lists --- fdroidserver/metadata.py | 17 ++++++++--- tests/metadata.TestCase | 61 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index f85ede04..49c34678 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -1091,14 +1091,23 @@ def parse_yaml_metadata(mf, app): _("Unrecognised build flag '{build_flag}' " "in '{path}'").format(build_flag=build_flag, path=mf.name)) - - if 'prebuild' in build and type(build['prebuild']) == list: - build['prebuild'] = ' && '.join(build['prebuild']) - + post_parse_yaml_metadata(yamldata) app.update(yamldata) return app +def post_parse_yaml_metadata(yamldata): + """transform yaml metadata to our internal data format""" + for build in yamldata.get('Builds', []): + for flag in build.keys(): + _flagtype = flagtype(flag) + + # concatenate script flags into a single string if they are stored as list + if _flagtype is TYPE_SCRIPT: + if isinstance(build[flag], list): + build[flag] = ' && '.join(build[flag]) + + def write_yaml(mf, app): """Write metadata in yaml format. diff --git a/tests/metadata.TestCase b/tests/metadata.TestCase index bedceb24..486dca09 100755 --- a/tests/metadata.TestCase +++ b/tests/metadata.TestCase @@ -216,21 +216,74 @@ class MetadataTest(unittest.TestCase): Builds: - versionCode: 1 versionName: v0.1.0 + sudo: + - apt-get update + - apt-get install -y whatever + - sed -i -e 's/> /a/file + build: + - ./gradlew someSpecialTask + - sed -i 'd/that wrong config/' gradle.properties + - ./gradlew compile """)) mf.name = 'mock_filename.yaml' mf.seek(0) result = {} with mock.patch('fdroidserver.metadata.warnings_action', 'error'): fdroidserver.metadata.parse_yaml_metadata(mf, result) + self.maxDiff = None self.assertDictEqual(result, {'AutoName': 'F-Droid', 'RepoType': 'git', 'Builds': [{'versionCode': 1, 'versionName': 'v0.1.0', - 'prebuild': 'a && b && c'}]}) + 'sudo': "apt-get update && " + "apt-get install -y whatever && " + "sed -i -e 's/> /a/file", + 'build': "./gradlew someSpecialTask && " + "sed -i 'd/that wrong config/' gradle.properties && " + "./gradlew compile"}]}) + + def test_parse_yaml_metadata_prebuild_strings(self): + mf = io.StringIO(textwrap.dedent("""\ + AutoName: F-Droid + RepoType: git + Builds: + - versionCode: 1 + versionName: v0.1.0 + sudo: |- + apt-get update && apt-get install -y whatever && sed -i -e 's/> /a/file + build: |- + ./gradlew someSpecialTask && sed -i 'd/that wrong config/' gradle.properties && ./gradlew compile + """)) + mf.name = 'mock_filename.yaml' + mf.seek(0) + result = {} + with mock.patch('fdroidserver.metadata.warnings_action', 'error'): + fdroidserver.metadata.parse_yaml_metadata(mf, result) + self.maxDiff = None + self.assertDictEqual(result, {'AutoName': 'F-Droid', + 'RepoType': 'git', + 'Builds': [{'versionCode': 1, + 'versionName': 'v0.1.0', + 'sudo': "apt-get update && " + "apt-get install -y whatever && " + "sed -i -e 's/> /a/file", + 'build': "./gradlew someSpecialTask && " + "sed -i 'd/that wrong config/' gradle.properties && " + "./gradlew compile"}]}) def test_parse_yaml_metadata_prebuild_string(self): mf = io.StringIO(textwrap.dedent("""\