diff --git a/fdroidserver/checkupdates.py b/fdroidserver/checkupdates.py index 4d2e45ef..32bfdb84 100644 --- a/fdroidserver/checkupdates.py +++ b/fdroidserver/checkupdates.py @@ -130,7 +130,6 @@ def check_tags(app, pattern): try_init_submodules(app, last_build, vcs) - hpak = None htag = None hver = None hcode = "0" @@ -159,25 +158,52 @@ 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): - hpak = package - 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 not hpak: - return (None, "Couldn't find package ID", None) if hver: return (hver, hcode, htag) return (None, "Couldn't find any version information", None) @@ -240,9 +266,10 @@ def check_repomanifest(app, branch=None): if vercode: logging.debug("Manifest exists in subdir '{0}'. Found version {1} ({2})" .format(subdir, version, vercode)) - if int(vercode) > int(hcode): + i_vercode = common.version_code_string_to_int(vercode) + if i_vercode > common.version_code_string_to_int(hcode): hpak = package - hcode = str(int(vercode)) + hcode = str(i_vercode) hver = version if not hpak: diff --git a/tests/checkupdates.TestCase b/tests/checkupdates.TestCase index 87ccdb99..2f44f235 100755 --- a/tests/checkupdates.TestCase +++ b/tests/checkupdates.TestCase @@ -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__))