Merge branch 'update-create-template' into 'master'

make metadata template behave well for empty values

Closes #681

See merge request fdroid/fdroidserver!657
This commit is contained in:
Michael Pöhn 2019-07-24 11:02:38 +00:00
commit 39c589fb85
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'],
metatxt,
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:
f.write(metatxt)
else:

View File

@ -15,8 +15,10 @@ import tempfile
import unittest
import yaml
import zipfile
import textwrap
from binascii import unhexlify
from distutils.version import LooseVersion
from testcommon import TmpCwd
localmodule = os.path.realpath(
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)
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__":
os.chdir(os.path.dirname(__file__))