From cb368a674cac0a01e851663bec6e0a73ce9d1d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Thu, 2 Jul 2020 00:38:09 +0200 Subject: [PATCH] remove txt srclib support --- fdroidserver/metadata.py | 46 +-------------------- tests/metadata.TestCase | 88 ++-------------------------------------- 2 files changed, 4 insertions(+), 130 deletions(-) diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index 72678434..ffc5edf7 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -657,46 +657,6 @@ def description_html(s, linkres): return ps.text_html -def parse_txt_srclib(metadatapath): - - thisinfo = {} - - # Defaults for fields that come from metadata - thisinfo['RepoType'] = '' - thisinfo['Repo'] = '' - thisinfo['Subdir'] = None - thisinfo['Prepare'] = None - - if not os.path.exists(metadatapath): - return thisinfo - - metafile = open(metadatapath, "r") - - n = 0 - for line in metafile: - n += 1 - line = line.rstrip('\r\n') - if not line or line.startswith("#"): - continue - - try: - f, v = line.split(':', 1) - except ValueError: - warn_or_exception(_("Invalid metadata in %s:%d") % (line, n)) - - # collapse whitespaces in field names - f = f.replace(' ', '') - - if f == "Subdir": - thisinfo[f] = v.split(',') - else: - thisinfo[f] = v - - metafile.close() - - return thisinfo - - def parse_yaml_srclib(metadatapath): thisinfo = {'RepoType': '', @@ -752,7 +712,7 @@ def read_srclibs(): The information read will be accessible as metadata.srclibs, which is a dictionary, keyed on srclib name, with the values each being a dictionary - in the same format as that returned by the parse_txt_srclib function. + in the same format as that returned by the parse_yaml_srclib function. A MetaDataException is raised if there are any problems with the srclib metadata. @@ -769,10 +729,6 @@ def read_srclibs(): if not os.path.exists(srcdir): os.makedirs(srcdir) - for metadatapath in sorted(glob.glob(os.path.join(srcdir, '*.txt'))): - srclibname = os.path.basename(metadatapath[:-4]) - srclibs[srclibname] = parse_txt_srclib(metadatapath) - for metadatapath in sorted(glob.glob(os.path.join(srcdir, '*.yml'))): srclibname = os.path.basename(metadatapath[:-4]) srclibs[srclibname] = parse_yaml_srclib(metadatapath) diff --git a/tests/metadata.TestCase b/tests/metadata.TestCase index f9ba731d..8ab502c4 100755 --- a/tests/metadata.TestCase +++ b/tests/metadata.TestCase @@ -637,88 +637,6 @@ class MetadataTest(unittest.TestCase): UpdateCheckMode: None """)) - def test_parse_txt_srclib(self): - fdroidserver.metadata.warnings_action = 'error' - with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir): - with open('JSoup.txt', 'w', encoding='utf-8') as f: - f.write(textwrap.dedent('''\ - # Source details (the only mandatory fields) - Repo Type:git - Repo:https://github.com/jhy/jsoup.git - - # Comma-separated list of subdirs to use. The first existing subdirectory - # found between those given will be used. If none is found or provided, the - # root of the repo directory will be used instead. - Subdir: - - # Any extra commands to prepare the source library - Prepare: - ''')) - srclib = fdroidserver.metadata.parse_txt_srclib('JSoup.txt') - self.assertDictEqual({'Repo': 'https://github.com/jhy/jsoup.git', - 'RepoType': 'git', - 'Subdir': [''], - 'Prepare': ''}, - srclib) - - def test_parse_txt_srclib_simple(self): - fdroidserver.metadata.warnings_action = 'error' - with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir): - with open('simple.txt', 'w', encoding='utf-8') as f: - f.write(textwrap.dedent('''\ - # this should be simple - Repo Type:git - Repo:https://git.host/repo.git - ''')) - srclib = fdroidserver.metadata.parse_txt_srclib('simple.txt') - self.assertDictEqual({'Repo': 'https://git.host/repo.git', - 'RepoType': 'git', - 'Subdir': None, - 'Prepare': None}, - srclib) - - def test_parse_txt_srclib_simple_blanks(self): - fdroidserver.metadata.warnings_action = 'error' - with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir): - with open('simple.txt', 'w', encoding='utf-8') as f: - f.write(textwrap.dedent('''\ - # this should be simple - - Repo Type:git - - Repo:https://git.host/repo.git - - Subdir: - - Prepare: - ''')) - srclib = fdroidserver.metadata.parse_txt_srclib('simple.txt') - self.assertDictEqual({'Repo': 'https://git.host/repo.git', - 'RepoType': 'git', - 'Subdir': [''], - 'Prepare': ''}, - srclib) - - def test_parse_txt_srclib_Changelog_cketti(self): - fdroidserver.metadata.warnings_action = 'error' - with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir): - with open('Changelog-cketti.txt', 'w', encoding='utf-8') as f: - f.write(textwrap.dedent('''\ - Repo Type:git - Repo:https://github.com/cketti/ckChangeLog - - Subdir:library,ckChangeLog/src/main - Prepare:[ -f project.properties ] || echo 'source.dir=java' > ant.properties && echo -e 'android.library=true\\ntarget=android-19' > project.properties - ''')) - srclib = fdroidserver.metadata.parse_txt_srclib('Changelog-cketti.txt') - self.assertDictEqual({'Repo': 'https://github.com/cketti/ckChangeLog', - 'RepoType': 'git', - 'Subdir': ['library', 'ckChangeLog/src/main'], - 'Prepare': "[ -f project.properties ] || echo 'source.dir=java' > " - "ant.properties && echo -e " - "'android.library=true\\ntarget=android-19' > project.properties"}, - srclib) - def test_parse_yaml_srclib_unknown_key(self): fdroidserver.metadata.warnings_action = 'error' with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir): @@ -885,11 +803,11 @@ class MetadataTest(unittest.TestCase): RepoType: git Repo: https://git.host/repo.git ''')) - with open('srclibs/simple-wb.txt', 'w', encoding='utf-8') as f: + with open('srclibs/simple-wb.yml', 'w', encoding='utf-8') as f: f.write(textwrap.dedent('''\ # this should be simple - Repo Type:git - Repo:https://git.host/repo.git + RepoType: git + Repo: https://git.host/repo.git Subdir: Prepare: