mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-11 23:23:27 +02:00
metadata: normalize TYPE_BOOL to YAML 1.2 booleans
This makes the internal representation always be a boolean, and that also means that YAML 1.2 booleans will be written out, e.g. rewritemeta.
This commit is contained in:
parent
aa98d67c86
commit
8374842faa
@ -57,6 +57,7 @@ metadata_v0:
|
|||||||
- cd fdroiddata
|
- cd fdroiddata
|
||||||
- ../tests/dump_internal_metadata_format.py
|
- ../tests/dump_internal_metadata_format.py
|
||||||
- sed -i
|
- sed -i
|
||||||
|
-e '/RequiresRoot:/d'
|
||||||
-e "/buildozer/d"
|
-e "/buildozer/d"
|
||||||
-e '/^comments\W /d'
|
-e '/^comments\W /d'
|
||||||
-e 's,maven\(\W\) false,maven\1 null,'
|
-e 's,maven\(\W\) false,maven\1 null,'
|
||||||
|
@ -979,6 +979,8 @@ def post_parse_yaml_metadata(yamldata):
|
|||||||
elif _fieldtype == TYPE_STRINGMAP:
|
elif _fieldtype == TYPE_STRINGMAP:
|
||||||
if v or v == 0: # TODO probably want just `if v:`
|
if v or v == 0: # TODO probably want just `if v:`
|
||||||
yamldata[k] = _normalize_type_stringmap(k, v)
|
yamldata[k] = _normalize_type_stringmap(k, v)
|
||||||
|
elif _fieldtype == TYPE_BOOL:
|
||||||
|
yamldata[k] = bool(v)
|
||||||
else:
|
else:
|
||||||
if type(v) in (float, int):
|
if type(v) in (float, int):
|
||||||
yamldata[k] = str(v)
|
yamldata[k] = str(v)
|
||||||
@ -1017,6 +1019,8 @@ def post_parse_yaml_metadata(yamldata):
|
|||||||
elif _flagtype == TYPE_STRINGMAP:
|
elif _flagtype == TYPE_STRINGMAP:
|
||||||
if v or v == 0:
|
if v or v == 0:
|
||||||
build[k] = _normalize_type_stringmap(k, v)
|
build[k] = _normalize_type_stringmap(k, v)
|
||||||
|
elif _flagtype == TYPE_BOOL:
|
||||||
|
build[k] = bool(v)
|
||||||
|
|
||||||
builds.append(build)
|
builds.append(build)
|
||||||
|
|
||||||
|
@ -2014,7 +2014,7 @@ class PostMetadataParseTest(unittest.TestCase):
|
|||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
self._post_metadata_parse_app_list(123456, TypeError)
|
self._post_metadata_parse_app_list(123456, TypeError)
|
||||||
self.assertEqual(*self._post_metadata_parse_app_string(123456, '123456'))
|
self.assertEqual(*self._post_metadata_parse_app_string(123456, '123456'))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_bool(123456, 123456))
|
self.assertEqual(*self._post_metadata_parse_build_bool(123456, True))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_int(123456, 123456))
|
self.assertEqual(*self._post_metadata_parse_build_int(123456, 123456))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_list(123456, ['123456']))
|
self.assertEqual(*self._post_metadata_parse_build_list(123456, ['123456']))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_script(123456, ['123456']))
|
self.assertEqual(*self._post_metadata_parse_build_script(123456, ['123456']))
|
||||||
@ -2024,7 +2024,7 @@ class PostMetadataParseTest(unittest.TestCase):
|
|||||||
"""Run the int 0 through the various field and flag types."""
|
"""Run the int 0 through the various field and flag types."""
|
||||||
self.assertEqual(*self._post_metadata_parse_app_list(0, 0))
|
self.assertEqual(*self._post_metadata_parse_app_list(0, 0))
|
||||||
self.assertEqual(*self._post_metadata_parse_app_string(0, '0'))
|
self.assertEqual(*self._post_metadata_parse_app_string(0, '0'))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_bool(0, 0))
|
self.assertEqual(*self._post_metadata_parse_build_bool(0, False))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_int(0, 0))
|
self.assertEqual(*self._post_metadata_parse_build_int(0, 0))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_list(0, ['0']))
|
self.assertEqual(*self._post_metadata_parse_build_list(0, ['0']))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_script(0, ['0']))
|
self.assertEqual(*self._post_metadata_parse_build_script(0, ['0']))
|
||||||
@ -2034,7 +2034,7 @@ class PostMetadataParseTest(unittest.TestCase):
|
|||||||
"""Run the float 0.0 through the various field and flag types."""
|
"""Run the float 0.0 through the various field and flag types."""
|
||||||
self.assertEqual(*self._post_metadata_parse_app_list(0.0, 0.0))
|
self.assertEqual(*self._post_metadata_parse_app_list(0.0, 0.0))
|
||||||
self.assertEqual(*self._post_metadata_parse_app_string(0.0, '0.0'))
|
self.assertEqual(*self._post_metadata_parse_app_string(0.0, '0.0'))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_bool(0.0, 0.0))
|
self.assertEqual(*self._post_metadata_parse_build_bool(0.0, False))
|
||||||
with self.assertRaises(MetaDataException):
|
with self.assertRaises(MetaDataException):
|
||||||
self._post_metadata_parse_build_int(0.0, MetaDataException)
|
self._post_metadata_parse_build_int(0.0, MetaDataException)
|
||||||
self.assertEqual(*self._post_metadata_parse_build_list(0.0, 0.0))
|
self.assertEqual(*self._post_metadata_parse_build_list(0.0, 0.0))
|
||||||
@ -2046,7 +2046,7 @@ class PostMetadataParseTest(unittest.TestCase):
|
|||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
self._post_metadata_parse_app_list(0.1, TypeError)
|
self._post_metadata_parse_app_list(0.1, TypeError)
|
||||||
self.assertEqual(*self._post_metadata_parse_app_string(0.1, '0.1'))
|
self.assertEqual(*self._post_metadata_parse_app_string(0.1, '0.1'))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_bool(0.1, 0.1))
|
self.assertEqual(*self._post_metadata_parse_build_bool(0.1, True))
|
||||||
with self.assertRaises(MetaDataException):
|
with self.assertRaises(MetaDataException):
|
||||||
self._post_metadata_parse_build_int(0.1, MetaDataException)
|
self._post_metadata_parse_build_int(0.1, MetaDataException)
|
||||||
self.assertEqual(*self._post_metadata_parse_build_list(0.1, 0.1))
|
self.assertEqual(*self._post_metadata_parse_build_list(0.1, 0.1))
|
||||||
@ -2058,7 +2058,7 @@ class PostMetadataParseTest(unittest.TestCase):
|
|||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
self._post_metadata_parse_app_list(1.0, TypeError)
|
self._post_metadata_parse_app_list(1.0, TypeError)
|
||||||
self.assertEqual(*self._post_metadata_parse_app_string(1.0, '1.0'))
|
self.assertEqual(*self._post_metadata_parse_app_string(1.0, '1.0'))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_bool(1.0, 1.0))
|
self.assertEqual(*self._post_metadata_parse_build_bool(1.0, True))
|
||||||
with self.assertRaises(MetaDataException):
|
with self.assertRaises(MetaDataException):
|
||||||
self._post_metadata_parse_build_int(1.0, MetaDataException)
|
self._post_metadata_parse_build_int(1.0, MetaDataException)
|
||||||
self.assertEqual(*self._post_metadata_parse_build_list(1.0, 1.0))
|
self.assertEqual(*self._post_metadata_parse_build_list(1.0, 1.0))
|
||||||
@ -2068,7 +2068,7 @@ class PostMetadataParseTest(unittest.TestCase):
|
|||||||
def test_post_metadata_parse_empty_list(self):
|
def test_post_metadata_parse_empty_list(self):
|
||||||
self.assertEqual(*self._post_metadata_parse_app_list(list(), list()))
|
self.assertEqual(*self._post_metadata_parse_app_list(list(), list()))
|
||||||
self.assertEqual(*self._post_metadata_parse_app_string(list(), list()))
|
self.assertEqual(*self._post_metadata_parse_app_string(list(), list()))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_bool(list(), list()))
|
self.assertEqual(*self._post_metadata_parse_build_bool(list(), False))
|
||||||
with self.assertRaises(MetaDataException):
|
with self.assertRaises(MetaDataException):
|
||||||
self._post_metadata_parse_build_int(list(), MetaDataException)
|
self._post_metadata_parse_build_int(list(), MetaDataException)
|
||||||
self.assertEqual(*self._post_metadata_parse_build_list(list(), list()))
|
self.assertEqual(*self._post_metadata_parse_build_list(list(), list()))
|
||||||
@ -2078,7 +2078,7 @@ class PostMetadataParseTest(unittest.TestCase):
|
|||||||
def test_post_metadata_parse_set_of_1(self):
|
def test_post_metadata_parse_set_of_1(self):
|
||||||
self.assertEqual(*self._post_metadata_parse_app_list({1}, ['1']))
|
self.assertEqual(*self._post_metadata_parse_app_list({1}, ['1']))
|
||||||
self.assertEqual(*self._post_metadata_parse_app_string({1}, '{1}'))
|
self.assertEqual(*self._post_metadata_parse_app_string({1}, '{1}'))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_bool({1}, {1}))
|
self.assertEqual(*self._post_metadata_parse_build_bool({1}, True))
|
||||||
with self.assertRaises(MetaDataException):
|
with self.assertRaises(MetaDataException):
|
||||||
self._post_metadata_parse_build_int({1}, MetaDataException)
|
self._post_metadata_parse_build_int({1}, MetaDataException)
|
||||||
self.assertEqual(*self._post_metadata_parse_build_list({1}, {1}))
|
self.assertEqual(*self._post_metadata_parse_build_list({1}, {1}))
|
||||||
@ -2088,7 +2088,7 @@ class PostMetadataParseTest(unittest.TestCase):
|
|||||||
def test_post_metadata_parse_empty_dict(self):
|
def test_post_metadata_parse_empty_dict(self):
|
||||||
self.assertEqual(*self._post_metadata_parse_app_list(dict(), dict()))
|
self.assertEqual(*self._post_metadata_parse_app_list(dict(), dict()))
|
||||||
self.assertEqual(*self._post_metadata_parse_app_string(dict(), dict()))
|
self.assertEqual(*self._post_metadata_parse_app_string(dict(), dict()))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_bool(dict(), dict()))
|
self.assertEqual(*self._post_metadata_parse_build_bool(dict(), False))
|
||||||
with self.assertRaises(MetaDataException):
|
with self.assertRaises(MetaDataException):
|
||||||
self._post_metadata_parse_build_int(dict(), MetaDataException)
|
self._post_metadata_parse_build_int(dict(), MetaDataException)
|
||||||
self.assertEqual(*self._post_metadata_parse_build_list(dict(), dict()))
|
self.assertEqual(*self._post_metadata_parse_build_list(dict(), dict()))
|
||||||
@ -2098,7 +2098,7 @@ class PostMetadataParseTest(unittest.TestCase):
|
|||||||
def test_post_metadata_parse_list_int_string(self):
|
def test_post_metadata_parse_list_int_string(self):
|
||||||
self.assertEqual(*self._post_metadata_parse_app_list([1, 'a'], ['1', 'a']))
|
self.assertEqual(*self._post_metadata_parse_app_list([1, 'a'], ['1', 'a']))
|
||||||
self.assertEqual(*self._post_metadata_parse_app_string([1, 'a'], "[1, 'a']"))
|
self.assertEqual(*self._post_metadata_parse_app_string([1, 'a'], "[1, 'a']"))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_bool([1, 'a'], [1, 'a']))
|
self.assertEqual(*self._post_metadata_parse_build_bool([1, 'a'], True))
|
||||||
with self.assertRaises(MetaDataException):
|
with self.assertRaises(MetaDataException):
|
||||||
self._post_metadata_parse_build_int([1, 'a'], MetaDataException)
|
self._post_metadata_parse_build_int([1, 'a'], MetaDataException)
|
||||||
self.assertEqual(*self._post_metadata_parse_build_list([1, 'a'], [1, 'a']))
|
self.assertEqual(*self._post_metadata_parse_build_list([1, 'a'], [1, 'a']))
|
||||||
@ -2108,7 +2108,7 @@ class PostMetadataParseTest(unittest.TestCase):
|
|||||||
def test_post_metadata_parse_dict_int_string(self):
|
def test_post_metadata_parse_dict_int_string(self):
|
||||||
self.assertEqual(*self._post_metadata_parse_app_list({'k': 1}, ['k']))
|
self.assertEqual(*self._post_metadata_parse_app_list({'k': 1}, ['k']))
|
||||||
self.assertEqual(*self._post_metadata_parse_app_string({'k': 1}, "{'k': 1}"))
|
self.assertEqual(*self._post_metadata_parse_app_string({'k': 1}, "{'k': 1}"))
|
||||||
self.assertEqual(*self._post_metadata_parse_build_bool({'k': 1}, {'k': 1}))
|
self.assertEqual(*self._post_metadata_parse_build_bool({'k': 1}, True))
|
||||||
with self.assertRaises(MetaDataException):
|
with self.assertRaises(MetaDataException):
|
||||||
self._post_metadata_parse_build_int({'k': 1}, MetaDataException)
|
self._post_metadata_parse_build_int({'k': 1}, MetaDataException)
|
||||||
self.assertEqual(*self._post_metadata_parse_build_list({'k': 1}, {'k': 1}))
|
self.assertEqual(*self._post_metadata_parse_build_list({'k': 1}, {'k': 1}))
|
||||||
|
Loading…
Reference in New Issue
Block a user