make versionCode/build.timeout an integer

Co-authored-by: Jochen Sprickerhof <git@jochen.sprickerhof.de>
This commit is contained in:
linsui 2022-09-14 09:45:24 +08:00 committed by Jochen Sprickerhof
parent 6f73a87eb1
commit 5a28f20301
20 changed files with 308 additions and 295 deletions

View file

@ -336,7 +336,7 @@ def transform_first_char(string, method):
def add_failed_builds_entry(failed_builds, appid, build, entry):
failed_builds.append([appid, int(build.versionCode), str(entry)])
failed_builds.append([appid, build.versionCode, str(entry)])
def get_metadata_from_apk(app, build, apkfile):
@ -807,10 +807,10 @@ def build_local(app, build, vcs, build_dir, output_dir, log_dir, srclib_dir, ext
vercode, version = get_metadata_from_apk(app, build, src)
if version != build.versionName or vercode != build.versionCode:
raise BuildException(("Unexpected version/version code in output;"
" APK: '%s' / '%s', "
" Expected: '%s' / '%s'")
% (version, str(vercode), build.versionName,
str(build.versionCode)))
" APK: '%s' / '%d', "
" Expected: '%s' / '%d'")
% (version, vercode, build.versionName,
build.versionCode))
if (options.scan_binary or config.get('scan_binary')) and not options.skipscan:
if scanner.scan_binary(src):
raise BuildException("Found blocklisted packages in final apk!")
@ -1096,7 +1096,7 @@ def main():
if build.timeout is None:
timeout = 7200
else:
timeout = int(build.timeout)
timeout = build.timeout
if options.server and timeout > 0:
logging.debug(_('Setting {0} sec timeout for this build').format(timeout))
timer = threading.Timer(timeout, force_halt_build, [timeout])

View file

@ -65,7 +65,7 @@ def check_http(app):
m = re.search(codeex, page)
if not m:
raise FDroidException("No RE match for version code")
vercode = m.group(1).strip()
vercode = common.version_code_string_to_int(m.group(1).strip())
if urlver != '.':
logging.debug("...requesting {0}".format(urlver))
@ -116,7 +116,7 @@ def check_tags(app, pattern):
htag = None
hver = None
hcode = "0"
hcode = 0
tags = []
if repotype == 'git':
@ -181,10 +181,10 @@ def check_tags(app, pattern):
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):
vercode = common.version_code_string_to_int(vercode)
if vercode > hcode:
htag = tag
hcode = str(i_vercode)
hcode = vercode
hver = version
else:
for subdir in possible_subdirs(app):
@ -196,10 +196,9 @@ def check_tags(app, pattern):
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):
if vercode > hcode:
htag = tag
hcode = str(i_vercode)
hcode = vercode
hver = version
if hver:
@ -255,7 +254,7 @@ def check_repomanifest(app, branch=None):
hpak = None
hver = None
hcode = "0"
hcode = 0
for subdir in possible_subdirs(app):
root_dir = build_dir / subdir
paths = common.manifest_paths(root_dir, last_build.gradle)
@ -263,10 +262,9 @@ def check_repomanifest(app, branch=None):
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):
if vercode > hcode:
hpak = package
hcode = str(i_vercode)
hcode = vercode
hver = version
if not hpak:
@ -460,11 +458,11 @@ def checkupdates_app(app):
raise FDroidException(_('no version information found'))
elif vercode == app.CurrentVersionCode:
logging.debug("...up to date")
elif int(vercode) > int(app.CurrentVersionCode):
elif vercode > app.CurrentVersionCode:
logging.debug("...updating - old vercode={0}, new vercode={1}".format(
app.CurrentVersionCode, vercode))
app.CurrentVersion = version
app.CurrentVersionCode = str(int(vercode))
app.CurrentVersionCode = vercode
updating = True
else:
raise FDroidException(
@ -501,12 +499,12 @@ def checkupdates_app(app):
gotcur = False
latest = None
for build in app.get('Builds', []):
if int(build.versionCode) >= int(app.CurrentVersionCode):
if build.versionCode >= app.CurrentVersionCode:
gotcur = True
if not latest or int(build.versionCode) > int(latest.versionCode):
if not latest or build.versionCode > latest.versionCode:
latest = build
if int(latest.versionCode) > int(app.CurrentVersionCode):
if latest.versionCode > app.CurrentVersionCode:
raise FDroidException(
_(
'latest build recipe is newer: old vercode={old}, new vercode={new}'
@ -517,13 +515,15 @@ def checkupdates_app(app):
newbuild = copy.deepcopy(latest)
newbuild.disable = False
newbuild.versionCode = app.CurrentVersionCode
newbuild.versionName = app.CurrentVersion + suffix.replace('%c', newbuild.versionCode)
newbuild.versionName = app.CurrentVersion + suffix.replace(
'%c', str(newbuild.versionCode)
)
logging.info("...auto-generating build for " + newbuild.versionName)
if tag:
newbuild.commit = tag
else:
commit = pattern.replace('%v', app.CurrentVersion)
commit = commit.replace('%c', newbuild.versionCode)
commit = pattern.replace('%v', str(app.CurrentVersion))
commit = commit.replace('%c', str(newbuild.versionCode))
newbuild.commit = commit
app['Builds'].append(newbuild)

View file

@ -712,11 +712,7 @@ def read_pkg_args(appid_versionCode_pairs, allow_vercodes=False):
p = apk_regex.sub(r':\1', p)
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)
vercode = version_code_string_to_int(vercode)
else:
package, vercode = p, None
if package not in vercodes:
@ -819,7 +815,7 @@ def publishednameinfo(filename):
filename = os.path.basename(filename)
m = publish_name_regex.match(filename)
try:
result = (m.group(1), m.group(2))
result = (m.group(1), int(m.group(2)))
except AttributeError as exc:
raise FDroidException(_("Invalid name for published file: %s") % filename) from exc
return result
@ -846,10 +842,10 @@ def apk_parse_release_filename(apkname):
"""
m = apk_release_filename_with_sigfp.match(apkname)
if m:
return m.group('appid'), m.group('vercode'), m.group('sigfp')
return m.group('appid'), int(m.group('vercode')), m.group('sigfp')
m = apk_release_filename.match(apkname)
if m:
return m.group('appid'), m.group('vercode'), None
return m.group('appid'), int(m.group('vercode')), None
return None, None, None
@ -1803,7 +1799,7 @@ def parse_androidmanifests(paths, app):
matches = vcsearch_g(line)
if matches:
vercode = matches.group(1)
vercode = version_code_string_to_int(matches.group(1))
if inside_required_flavour > 0:
if '{' in line:
@ -1841,7 +1837,7 @@ def parse_androidmanifests(paths, app):
if not vercode:
matches = vcsearch_g(line)
if matches:
vercode = matches.group(1)
vercode = version_code_string_to_int(matches.group(1))
if not android_plugin_file and ANDROID_PLUGIN_REGEX.match(line):
android_plugin_file = True
if android_plugin_file:
@ -1868,9 +1864,8 @@ def parse_androidmanifests(paths, app):
base_dir = os.path.dirname(path)
version = retrieve_string_singleline(base_dir, version)
if XMLNS_ANDROID + "versionCode" in xml.attrib:
a = xml.attrib[XMLNS_ANDROID + "versionCode"]
if string_is_integer(a):
vercode = a
vercode = version_code_string_to_int(
xml.attrib[XMLNS_ANDROID + "versionCode"])
# Remember package name, may be defined separately from version+vercode
if package is None:
@ -2635,9 +2630,9 @@ def get_apk_id_androguard(apkfile):
appid = value
elif versionCode is None and name == 'versionCode':
if value.startswith('0x'):
versionCode = str(int(value, 16))
versionCode = int(value, 16)
else:
versionCode = value
versionCode = int(value)
elif versionName is None and name == 'versionName':
versionName = value
@ -2657,12 +2652,15 @@ def get_apk_id_androguard(apkfile):
def get_apk_id_aapt(apkfile):
"""Read (appid, versionCode, versionName) from an APK."""
p = SdkToolsPopen(['aapt', 'dump', 'badging', apkfile], output=False)
m = APK_ID_TRIPLET_REGEX.match(p.output[0:p.output.index('\n')])
if m:
return m.group(1), m.group(2), m.group(3)
raise FDroidException(_("Reading packageName/versionCode/versionName failed, APK invalid: '{apkfilename}'")
.format(apkfilename=apkfile))
return m.group(1), int(m.group(2)), m.group(3)
raise FDroidException(_(
"Reading packageName/versionCode/versionName failed,"
"APK invalid: '{apkfilename}'"
).format(apkfilename=apkfile))
def get_native_code(apkfile):
@ -3859,6 +3857,8 @@ def string_is_integer(string):
def version_code_string_to_int(vercode):
"""Convert an version code string of any base into an int."""
# TODO: Python 3.6 allows underscores in numeric literals
vercode = vercode.replace('_', '')
try:
return int(vercode, 0)
except ValueError:

View file

@ -311,7 +311,7 @@ def main():
# Create a build line...
build.versionName = versionName or 'Unknown'
build.versionCode = versionCode or '0' # TODO heinous but this is still a str
build.versionCode = versionCode or 0
if options.subdir:
build.subdir = options.subdir
build.gradle = ['yes']

View file

@ -637,7 +637,7 @@ def convert_version(version, app, repodir):
manifest[element] = version[element]
if "versionCode" in version:
manifest["versionCode"] = int(version["versionCode"])
manifest["versionCode"] = version["versionCode"]
if "features" in version and version["features"]:
manifest["features"] = features = []
@ -684,12 +684,11 @@ def convert_version(version, app, repodir):
ver["antiFeatures"][antif] = {}
if "versionCode" in version:
if int(version["versionCode"]) > int(app["CurrentVersionCode"]):
if version["versionCode"] > app["CurrentVersionCode"]:
ver["releaseChannels"] = ["Beta"]
versionCodeStr = str(version['versionCode']) # TODO build.versionCode should be int!
for build in app.get('Builds', []):
if build['versionCode'] == versionCodeStr and "whatsNew" in build:
if build['versionCode'] == version['versionCode'] and "whatsNew" in build:
ver["whatsNew"] = build["whatsNew"]
break
@ -770,9 +769,8 @@ def make_v2(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
continue
if not package.get('versionName'):
app = apps[packageName]
versionCodeStr = str(package['versionCode']) # TODO build.versionCode should be int!
for build in app.get('Builds', []):
if build['versionCode'] == versionCodeStr:
if build['versionCode'] == package['versionCode']:
versionName = build.get('versionName')
logging.info(_('Overriding blank versionName in {apkfilename} from metadata: {version}')
.format(apkfilename=package['apkName'], version=versionName))
@ -905,6 +903,7 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
k = 'packageName'
elif k == 'CurrentVersionCode': # TODO make SuggestedVersionCode the canonical name
k = 'suggestedVersionCode'
v = str(v)
elif k == 'CurrentVersion': # TODO make SuggestedVersionName the canonical name
k = 'suggestedVersionName'
else:
@ -931,9 +930,8 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
continue
if not package.get('versionName'):
app = apps[packageName]
versionCodeStr = str(package['versionCode']) # TODO build.versionCode should be int!
for build in app.get('Builds', []):
if build['versionCode'] == versionCodeStr:
if build['versionCode'] == package['versionCode']:
versionName = build.get('versionName')
logging.info(_('Overriding blank versionName in {apkfilename} from metadata: {version}')
.format(apkfilename=package['apkName'], version=versionName))
@ -1013,7 +1011,7 @@ def v1_sort_packages(packages, fdroid_signing_key_fingerprints):
versionCode = None
if package.get('versionCode', None):
versionCode = -int(package['versionCode'])
versionCode = -package['versionCode']
return packageName, group, signer, versionCode
@ -1179,7 +1177,7 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
# one is recommended. They are historically mis-named, and need
# changing, but stay like this for now to support existing clients.
addElement('marketversion', app.CurrentVersion, doc, apel)
addElement('marketvercode', app.CurrentVersionCode, doc, apel)
addElement('marketvercode', str(app.CurrentVersionCode), doc, apel)
if app.Provides:
pv = app.Provides.split(',')
@ -1214,7 +1212,7 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
for apk in apklist:
file_extension = common.get_file_extension(apk['apkName'])
# find the APK for the "Current Version"
if current_version_code < int(app.CurrentVersionCode):
if current_version_code < app.CurrentVersionCode:
current_version_file = apk['apkName']
if current_version_code < apk['versionCode']:
current_version_code = apk['versionCode']
@ -1224,9 +1222,11 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
versionName = apk.get('versionName')
if not versionName:
versionCodeStr = str(apk['versionCode']) # TODO build.versionCode should be int!
for build in app.get('Builds', []):
if build['versionCode'] == versionCodeStr and 'versionName' in build:
if (
build['versionCode'] == apk['versionCode']
and 'versionName' in build
):
versionName = build['versionName']
break
if versionName:

View file

@ -240,10 +240,10 @@ def get_lastbuild(builds):
lastbuild = None
for build in builds:
if not build.disable:
vercode = int(build.versionCode)
vercode = build.versionCode
if lowest_vercode == -1 or vercode < lowest_vercode:
lowest_vercode = vercode
if not lastbuild or int(build.versionCode) > int(lastbuild.versionCode):
if not lastbuild or build.versionCode > lastbuild.versionCode:
lastbuild = build
return lastbuild
@ -327,13 +327,10 @@ filling_ucms = re.compile(r'^(Tags.*|RepoManifest.*)')
def check_checkupdates_ran(app):
if filling_ucms.match(app.UpdateCheckMode):
if (
not app.AutoName
and not app.CurrentVersion
and app.CurrentVersionCode == '0'
):
if not app.AutoName and not app.CurrentVersion and app.CurrentVersionCode == 0:
yield _(
"UpdateCheckMode is set but it looks like checkupdates hasn't been run yet"
"UpdateCheckMode is set but it looks like"
"checkupdates hasn't been run yet"
)
@ -637,7 +634,7 @@ def check_current_version_code(app):
if archive_policy and archive_policy.split()[0] == "0":
return
cv = app.get('CurrentVersionCode')
if cv is not None and int(cv) == 0:
if cv is not None and cv == 0:
return
builds = app.get('Builds')
@ -645,7 +642,7 @@ def check_current_version_code(app):
min_versionCode = None
if builds:
for build in builds:
vc = int(build['versionCode'])
vc = build['versionCode']
if min_versionCode is None or min_versionCode > vc:
min_versionCode = vc
if not build.get('disable'):
@ -654,7 +651,7 @@ def check_current_version_code(app):
break
if active_builds == 0:
return # all builds are disabled
if cv is not None and int(cv) < min_versionCode:
if cv is not None and cv < min_versionCode:
yield (
_(
'CurrentVersionCode {cv} is less than oldest build entry {versionCode}'

View file

@ -204,6 +204,7 @@ fieldtypes = {
'AntiFeatures': TYPE_LIST,
'AllowedAPKSigningKeys': TYPE_LIST,
'Builds': TYPE_BUILD,
'CurrentVersionCode': TYPE_INT,
}
@ -615,29 +616,31 @@ def split_list_values(s):
def sorted_builds(builds):
return sorted(builds, key=lambda build: int(build.versionCode))
return sorted(builds, key=lambda build: build.versionCode)
esc_newlines = re.compile(r'\\( |\n)')
def post_metadata_parse(app):
# TODO keep native types, convert only for .txt metadata
for k, v in app.items():
if type(v) in (float, int):
app[k] = str(v)
if 'flavours' in app and app['flavours'] == [True]:
app['flavours'] = 'yes'
for field, fieldtype in fieldtypes.items():
if fieldtype != TYPE_LIST:
continue
value = app.get(field)
if isinstance(value, str):
app[field] = [value, ]
elif value is not None:
app[field] = [str(i) for i in value]
for k, v in app.items():
if fieldtype(k) == TYPE_LIST:
if isinstance(v, str):
app[k] = [v, ]
elif v:
app[k] = [str(i) for i in v]
elif fieldtype(k) == TYPE_INT:
if v:
app[k] = int(v)
elif fieldtype(k) == TYPE_STRING:
if v:
app[k] = str(v)
else:
if type(v) in (float, int):
app[k] = str(v)
def _yaml_bool_unmapable(v):
return v in (True, False, [True], [False])
@ -673,7 +676,7 @@ def post_metadata_parse(app):
else:
build[k] = []
elif flagtype(k) is TYPE_INT:
build[k] = str(v)
build[k] = v
elif flagtype(k) is TYPE_STRING:
if isinstance(v, bool) and k in _bool_allowed:
build[k] = v

View file

@ -168,7 +168,7 @@ def status_update_json(apps, apks):
gotcurrentver = False
for apk in apks:
if apk['packageName'] == appid:
if str(apk['versionCode']) == app.get('CurrentVersionCode'):
if apk['versionCode'] == app.get('CurrentVersionCode'):
gotcurrentver = True
apklist.append(apk)
validapks = 0
@ -181,7 +181,7 @@ def status_update_json(apps, apks):
if not build.get('disable'):
builtit = False
for apk in apklist:
if apk['versionCode'] == int(build.versionCode):
if apk['versionCode'] == build.versionCode:
builtit = True
validapks += 1
break
@ -493,8 +493,9 @@ def insert_obbs(repodir, apps, apks):
if packagename == apk['packageName'] and apk['versionCode'] > highestVersionCode:
highestVersionCode = apk['versionCode']
if versionCode > highestVersionCode:
obbWarnDelete(f, _('OBB file has newer versionCode({integer}) than any APK:')
.format(integer=str(versionCode)))
obbWarnDelete(f, _(
'OBB file has newer versionCode({integer}) than any APK:'
).format(integer=versionCode))
continue
obbsha256 = common.sha256sum(f)
obbs.append((packagename, versionCode, obbfile, obbsha256))
@ -533,7 +534,7 @@ def translate_per_build_anti_features(apps, apks):
for build in app.get('Builds', []):
afl = build.get('antifeatures')
if afl:
d[int(build.versionCode)] = afl
d[build.versionCode] = afl
if len(d) > 0:
antiFeatures[packageName] = d
@ -569,7 +570,7 @@ def _set_localized_text_entry(app, locale, key, f, versionCode=None):
text = fp.read(limit * 2)
if versionCode:
for build in app["Builds"]:
if int(build["versionCode"]) == versionCode:
if build["versionCode"] == versionCode:
if "whatsNew" not in build:
build["whatsNew"] = collections.OrderedDict()
build["whatsNew"][locale] = text[:limit]
@ -1002,9 +1003,16 @@ def insert_localized_app_metadata(apps):
try:
versionCode = int(base)
locale = segments[-2]
if base in [a["versionCode"] for a in apps[packageName]["Builds"]]:
_set_localized_text_entry(apps[packageName], locale, 'whatsNew',
os.path.join(root, f), versionCode)
if versionCode in [
a["versionCode"] for a in apps[packageName]["Builds"]
]:
_set_localized_text_entry(
apps[packageName],
locale,
'whatsNew',
os.path.join(root, f),
versionCode,
)
continue
except ValueError:
pass
@ -1477,7 +1485,7 @@ def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=Fal
if apps:
if apk['packageName'] in apps:
for build in apps[apk['packageName']].get('Builds', []):
if int(build['versionCode']) == apk['versionCode'] and build['disable']:
if build['versionCode'] == apk['versionCode'] and build['disable']:
return True, None, False
# Check for debuggable apks...
@ -1809,7 +1817,7 @@ def apply_info_from_latest_apk(apps, apks):
else:
app.icon = bestapk['icon'] if 'icon' in bestapk else None
if app.get('CurrentVersionCode') is None:
app['CurrentVersionCode'] = str(bestver)
app['CurrentVersionCode'] = bestver
def make_categories_txt(repodir, categories):
@ -1828,7 +1836,7 @@ def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversi
for apk in apk_list:
if apk['packageName'] == appid:
if app.get('CurrentVersionCode') is not None:
if apk['versionCode'] == common.version_code_string_to_int(app['CurrentVersionCode']):
if apk['versionCode'] == app['CurrentVersionCode']:
currentVersionApk = apk
continue
apkList.append(apk)