1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-05 10:40:10 +02:00

Merge branch 'hex_versionCode' into 'master'

* hex_versionCode:
  checkupdates: split out vercode parsing into testable function
  Add unit test for string_is_integer()
  Support hex versionCode in build command line
  Support hex in versionCode

See merge request fdroid/fdroidserver!692
This commit is contained in:
Hans-Christoph Steiner 2019-12-03 23:55:12 +01:00
commit 37ca21f6da
No known key found for this signature in database
GPG Key ID: 3E177817BA1B9BFA
3 changed files with 38 additions and 4 deletions

View File

@ -168,10 +168,11 @@ def check_tags(app, pattern):
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
htag = tag
hcode = str(int(vercode))
hcode = str(i_vercode)
hver = version
if not hpak:

View File

@ -497,6 +497,11 @@ def read_pkg_args(appid_versionCode_pairs, allow_vercodes=False):
for p in appid_versionCode_pairs:
if allow_vercodes and ':' in p:
package, vercode = p.split(':')
try:
i_vercode = int(vercode, 0)
except ValueError:
i_vercode = int(vercode)
vercode = str(i_vercode)
else:
package, vercode = p, None
if package not in vercodes:
@ -3209,10 +3214,22 @@ def parse_xml(path):
def string_is_integer(string):
try:
int(string)
int(string, 0)
return True
except ValueError:
return False
try:
int(string)
return True
except ValueError:
return False
def version_code_string_to_int(vercode):
"""Convert an version code string of any base into an int"""
try:
return int(vercode, 0)
except ValueError:
return int(vercode)
def local_rsync(options, fromdir, todir):

View File

@ -1076,6 +1076,22 @@ class CommonTest(unittest.TestCase):
with gzip.open(expected_log_path, 'r') as f:
self.assertEqual(f.read(), mocklogcontent)
def test_string_is_integer(self):
self.assertTrue(fdroidserver.common.string_is_integer('0x10'))
self.assertTrue(fdroidserver.common.string_is_integer('010'))
self.assertTrue(fdroidserver.common.string_is_integer('123'))
self.assertFalse(fdroidserver.common.string_is_integer('0xgg'))
self.assertFalse(fdroidserver.common.string_is_integer('01g'))
self.assertFalse(fdroidserver.common.string_is_integer('o123'))
def test_version_code_string_to_int(self):
self.assertEqual(16, fdroidserver.common.version_code_string_to_int('0x10'))
self.assertEqual(198712389, fdroidserver.common.version_code_string_to_int('198712389'))
self.assertEqual(8, fdroidserver.common.version_code_string_to_int('0o10'))
self.assertEqual(10, fdroidserver.common.version_code_string_to_int('010'))
self.assertEqual(123, fdroidserver.common.version_code_string_to_int('0000123'))
self.assertEqual(-42, fdroidserver.common.version_code_string_to_int('-42'))
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))