mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-24 00:17:37 +01:00
ba47304803
GitOrigin-RevId: cf0b65f18564a17e5fd01068ef18276e920cbd19
63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
# General starlark utility functions
|
|
|
|
def retry_download_and_extract(ctx, tries, **kwargs):
|
|
sleep_time = 1
|
|
for attempt in range(tries):
|
|
is_retriable = attempt + 1 < tries
|
|
result = ctx.download_and_extract(allow_fail = is_retriable, **kwargs)
|
|
if result.success:
|
|
return result
|
|
else:
|
|
print("Download failed (Attempt #%s), sleeping for %s seconds then retrying..." % (attempt + 1, sleep_time))
|
|
ctx.execute(["sleep", str(sleep_time)])
|
|
sleep_time *= 2
|
|
|
|
def get_host_distro_major_version(repository_ctx):
|
|
_DISTRO_PATTERN_MAP = {
|
|
"Ubuntu 18*": "ubuntu18",
|
|
"Ubuntu 20*": "ubuntu20",
|
|
"Ubuntu 22*": "ubuntu22",
|
|
"Pop!_OS 22*": "ubuntu22",
|
|
"Ubuntu 24*": "ubuntu24",
|
|
"Amazon Linux 2": "amazon_linux_2",
|
|
"Amazon Linux 2023": "amazon_linux_2023",
|
|
"Debian GNU/Linux 10": "debian10",
|
|
"Debian GNU/Linux 12": "debian12",
|
|
"Red Hat Enterprise Linux 8*": "rhel8",
|
|
"Red Hat Enterprise Linux 9*": "rhel9",
|
|
"SLES 15*": "suse15",
|
|
}
|
|
|
|
if repository_ctx.os.name != "linux":
|
|
return None
|
|
|
|
result = repository_ctx.execute([
|
|
"sed",
|
|
"-n",
|
|
"/^\\(NAME\\|VERSION_ID\\)=/{s/[^=]*=//;s/\"//g;p}",
|
|
"/etc/os-release",
|
|
])
|
|
|
|
if result.return_code != 0:
|
|
print("Failed to determine system distro, parsing os-release failed with the error: " + result.stderr)
|
|
return None
|
|
|
|
distro_seq = result.stdout.splitlines()
|
|
if len(distro_seq) != 2:
|
|
print("Failed to determine system distro, parsing os-release returned: " + result.stdout)
|
|
return None
|
|
|
|
distro_str = "{distro_name} {distro_version}".format(
|
|
distro_name = distro_seq[0],
|
|
distro_version = distro_seq[1],
|
|
)
|
|
|
|
for distro_pattern, simplified_name in _DISTRO_PATTERN_MAP.items():
|
|
if "*" in distro_pattern:
|
|
prefix_suffix = distro_pattern.split("*")
|
|
if distro_str.startswith(prefix_suffix[0]) and distro_str.endswith(prefix_suffix[1]):
|
|
return simplified_name
|
|
elif distro_str == distro_pattern:
|
|
return simplified_name
|
|
return None
|