From dcf3837bcbebd0f1d0e77f942c0d867162e3dc71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Mon, 15 Jul 2019 15:45:02 +0200 Subject: [PATCH] parse yaml: ignore (and warn) deprecated field: Provides --- fdroidserver/metadata.py | 19 ++++++++++++++++--- tests/metadata.TestCase | 7 ++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index b228c924..d08f4102 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -1071,12 +1071,25 @@ def parse_json_metadata(mf, app): def parse_yaml_metadata(mf, app): yamldata = yaml.safe_load(mf) + deprecated_in_yaml = ['Provides'] + if yamldata: for field in yamldata: if field not in yaml_app_fields: - warn_or_exception(_("Unrecognised app field '{fieldname}' " - "in '{path}'").format(fieldname=field, - path=mf.name)) + if field not in deprecated_in_yaml: + warn_or_exception(_("Unrecognised app field " + "'{fieldname}' in '{path}'") + .format(fieldname=field, + path=mf.name)) + + for deprecated_field in deprecated_in_yaml: + if deprecated_field in yamldata: + logging.warning(_("Ignoring '{field}' in '{metapath}' " + "metadata because it is deprecated.") + .format(field=deprecated_field, + metapath=mf.name)) + del(yamldata[deprecated_field]) + if yamldata.get('Builds', None): for build in yamldata.get('Builds', []): # put all build flag keywords into a set to avoid diff --git a/tests/metadata.TestCase b/tests/metadata.TestCase index 68e402ab..686301db 100755 --- a/tests/metadata.TestCase +++ b/tests/metadata.TestCase @@ -367,7 +367,7 @@ class MetadataTest(unittest.TestCase): 'prebuild': "a && b && " "sed -i 's,a,b,'"}]}) - def test_parse_yaml_provides_should_raise_exception(self): + def test_parse_yaml_provides_should_be_ignored(self): mf = io.StringIO(textwrap.dedent("""\ Provides: this.is.deprecated AutoName: F-Droid @@ -382,8 +382,9 @@ class MetadataTest(unittest.TestCase): mf.seek(0) result = {} with mock.patch('fdroidserver.metadata.warnings_action', 'error'): - with self.assertRaises(fdroidserver.metadata.MetaDataException): - fdroidserver.metadata.parse_yaml_metadata(mf, result) + fdroidserver.metadata.parse_yaml_metadata(mf, result) + self.assertNotIn('Provides', result) + self.assertNotIn('provides', result) def test_write_yaml_1_line_scripts_as_string(self): mf = io.StringIO()