From 5741e6930b853a97c14bb36b561c4eacd76ad414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Sat, 29 Feb 2020 15:50:06 +0100 Subject: [PATCH] yml srclibs: support Subdir as list --- fdroidserver/metadata.py | 7 ++++++- tests/metadata.TestCase | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index e86faa70..3f79db43 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -778,7 +778,12 @@ def parse_yml_srclib(metadatapath): return thisinfo else: if key == 'Subdir': - thisinfo[key] = str(data[key] or '').split(',') + if isinstance(data[key], str): + thisinfo[key] = data[key].split(',') + elif isinstance(data[key], list): + thisinfo[key] = data[key] + elif data[key] is None: + thisinfo[key] = [''] elif key == 'Prepare' and isinstance(data[key], list): thisinfo[key] = ' && '.join(data[key]) else: diff --git a/tests/metadata.TestCase b/tests/metadata.TestCase index 7e7edcf8..dedbdd3f 100755 --- a/tests/metadata.TestCase +++ b/tests/metadata.TestCase @@ -733,6 +733,44 @@ class MetadataTest(unittest.TestCase): "ant.properties && echo -e " "'android.library=true\\ntarget=android-19' > project.properties"}) + def test_read_srclibs_yml_subdir_list(self): + fdroidserver.metadata.warnings_action = 'error' + fdroidserver.metadata.srclibs = None + with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir): + os.mkdir('srclibs') + with open('srclibs/with-list.yml', 'w', encoding='utf-8') as f: + f.write(textwrap.dedent('''\ + # this should be simple + RepoType: git + Repo: https://git.host/repo.git + + Subdir: + - This is your last chance. + - After this, there is no turning back. + - You take the blue pill—the story ends, + - you wake up in your bed + - and believe whatever you want to believe. + - You take the red pill—you stay in Wonderland + - and I show you how deep the rabbit-hole goes. + Prepare: + There is a difference between knowing the path + and walking the path. + ''')) + fdroidserver.metadata.read_srclibs() + self.maxDiff = None + self.assertDictEqual(fdroidserver.metadata.srclibs, + {'with-list': {'RepoType': 'git', + 'Repo': 'https://git.host/repo.git', + 'Subdir': ['This is your last chance.', + 'After this, there is no turning back.', + 'You take the blue pill—the story ends,', + 'you wake up in your bed', + 'and believe whatever you want to believe.', + 'You take the red pill—you stay in Wonderland', + 'and I show you how deep the rabbit-hole goes.'], + 'Prepare': 'There is a difference between knowing the path ' + 'and walking the path.'}}) + def test_read_srclibs_yml_prepare_list(self): fdroidserver.metadata.warnings_action = 'error' fdroidserver.metadata.srclibs = None