Support UpdateCheckData in check_tags

This commit is contained in:
Jochen Sprickerhof 2021-05-18 10:21:05 +02:00
parent ba2b236e7b
commit 133b626b22
2 changed files with 66 additions and 15 deletions

View File

@ -158,21 +158,51 @@ def check_tags(app, pattern):
logging.debug("Check tag: '{0}'".format(tag))
vcs.gotorevision(tag)
for subdir in possible_subdirs(app):
if subdir == '.':
root_dir = build_dir
else:
root_dir = os.path.join(build_dir, subdir)
paths = common.manifest_paths(root_dir, last_build.gradle)
version, vercode, package = common.parse_androidmanifests(paths, app)
if vercode:
logging.debug("Manifest exists in subdir '{0}'. Found version {1} ({2})"
.format(subdir, version, vercode))
i_vercode = common.version_code_string_to_int(vercode)
if i_vercode > common.version_code_string_to_int(hcode):
htag = tag
hcode = str(i_vercode)
hver = version
if app.UpdateCheckData:
filecode, codeex, filever, verex = app.UpdateCheckData.split('|')
vercode = None
if len(filecode) > 0:
filecontent = open(os.path.join(build_dir, filecode)).read()
m = re.search(codeex, filecontent)
if not m:
raise FDroidException("No RE match for version code")
vercode = m.group(1).strip()
version = "??"
if len(filever) > 0:
if filever != '.':
filecontent = open(os.path.join(build_dir, filever)).read()
m = re.search(verex, filecontent)
if not m:
raise FDroidException("No RE match for version")
version = m.group(1)
if vercode:
logging.debug("UpdateCheckData found version {0} ({1})"
.format(version, vercode))
i_vercode = common.version_code_string_to_int(vercode)
if i_vercode > common.version_code_string_to_int(hcode):
htag = tag
hcode = str(i_vercode)
hver = version
else:
for subdir in possible_subdirs(app):
if subdir == '.':
root_dir = build_dir
else:
root_dir = os.path.join(build_dir, subdir)
paths = common.manifest_paths(root_dir, last_build.gradle)
version, vercode, package = common.parse_androidmanifests(paths, app)
if vercode:
logging.debug("Manifest exists in subdir '{0}'. Found version {1} ({2})"
.format(subdir, version, vercode))
i_vercode = common.version_code_string_to_int(vercode)
if i_vercode > common.version_code_string_to_int(hcode):
htag = tag
hcode = str(i_vercode)
hver = version
if hver:
return (hver, hcode, htag)

View File

@ -186,6 +186,27 @@ class CheckupdatesTest(unittest.TestCase):
self.assertEqual(vername, None)
self.assertEqual(vercode, 'Version 1.1.9-beta is ignored')
def test_check_tags_data(self):
fdroidserver.checkupdates.options = mock.Mock()
app = fdroidserver.metadata.App()
app.id = 'loop.starts.shooting'
app.metadatapath = 'metadata/' + app.id + '.yml'
app.RepoType = 'git'
app.CurrentVersionCode = 10108
app.UpdateCheckMode = 'Tags'
app.UpdateCheckData = 'b.txt|c(.*)|e.txt|v(.*)'
vcs = mock.Mock()
vcs.latesttags.return_value = ['1.1.8', '1.1.9']
with mock.patch(
'builtins.open', mock.mock_open(read_data='v1.1.9\nc10109')
) as _ignored, mock.patch('fdroidserver.common.getvcs', return_value=vcs):
_ignored # silence the linters
vername, vercode, tag = fdroidserver.checkupdates.check_tags(app, None)
self.assertEqual(vername, '1.1.9')
self.assertEqual(vercode, '10109')
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))