make metadata template behaves well for empty values

This commit is contained in:
Michael Pöhn 2019-07-22 01:34:55 +02:00
parent 051596dd0d
commit e2fed09af1
2 changed files with 88 additions and 0 deletions

View file

@ -1869,6 +1869,11 @@ def create_metadata_from_template(apk):
r'\1 ' + apk['packageName'], r'\1 ' + apk['packageName'],
metatxt, metatxt,
flags=re.IGNORECASE | re.MULTILINE) flags=re.IGNORECASE | re.MULTILINE)
# make sure unset string values will be interpreted as blank strings
str_fields = [x for x in metadata.yaml_app_fields if metadata.fieldtype(x) == metadata.TYPE_STRING]
metatxt = re.sub(r'^(' + '|'.join(str_fields) + '):\\s*$',
r"\1: ''", metatxt,
flags=re.MULTILINE)
with open(os.path.join('metadata', apk['packageName'] + '.yml'), 'w') as f: with open(os.path.join('metadata', apk['packageName'] + '.yml'), 'w') as f:
f.write(metatxt) f.write(metatxt)
else: else:

View file

@ -15,8 +15,10 @@ import tempfile
import unittest import unittest
import yaml import yaml
import zipfile import zipfile
import textwrap
from binascii import unhexlify from binascii import unhexlify
from distutils.version import LooseVersion from distutils.version import LooseVersion
from testcommon import TmpCwd
localmodule = os.path.realpath( localmodule = os.path.realpath(
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')) os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
@ -833,6 +835,87 @@ class UpdateTest(unittest.TestCase):
icons_src = fdroidserver.update._get_apk_icons_src('urzip-release.apk', None) icons_src = fdroidserver.update._get_apk_icons_src('urzip-release.apk', None)
assert icons_src == {} assert icons_src == {}
def test_create_metadata_from_template_empty_keys(self):
apk = {'packageName': 'rocks.janicerand'}
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
os.mkdir('metadata')
with open('template.yml', 'w') as f:
f.write(textwrap.dedent('''\
Disabled:
Provides:
License:
AuthorName:
AuthorEmail:
AuthorWebSite:
WebSite:
SourceCode:
IssueTracker:
Translation:
Changelog:
Donate:
FlattrID:
LiberapayID:
Bitcoin:
Litecoin:
Name:
AutoName:
Summary:
RequiresRoot:
RepoType:
Repo:
Binaries:
Builds:
ArchivePolicy:
AutoUpdateMode:
UpdateCheckMode:
UpdateCheckIgnore:
VercodeOperation:
UpdateCheckName:
UpdateCheckData:
CurrentVersion:
CurrentVersionCode:
NoSourceSince:
'''))
fdroidserver.update.create_metadata_from_template(apk)
with open(os.path.join('metadata', 'rocks.janicerand.yml')) as f:
metadata_content = yaml.load(f)
self.maxDiff = None
self.assertDictEqual(metadata_content,
{'ArchivePolicy': '',
'AuthorEmail': '',
'AuthorName': '',
'AuthorWebSite': '',
'AutoName': 'rocks.janicerand',
'AutoUpdateMode': '',
'Binaries': '',
'Bitcoin': '',
'Builds': '',
'Changelog': '',
'CurrentVersion': '',
'CurrentVersionCode': '',
'Disabled': '',
'Donate': '',
'FlattrID': '',
'IssueTracker': '',
'LiberapayID': '',
'License': '',
'Litecoin': '',
'Name': 'rocks.janicerand',
'NoSourceSince': '',
'Provides': '',
'Repo': '',
'RepoType': '',
'RequiresRoot': '',
'SourceCode': '',
'Summary': 'rocks.janicerand',
'Translation': '',
'UpdateCheckData': '',
'UpdateCheckIgnore': '',
'UpdateCheckMode': '',
'UpdateCheckName': '',
'VercodeOperation': '',
'WebSite': ''})
if __name__ == "__main__": if __name__ == "__main__":
os.chdir(os.path.dirname(__file__)) os.chdir(os.path.dirname(__file__))