install_linux_packages: Add fallback to identify known distro.
Python versions before 3.10 did not have the `platform.freedesktop_os_release` utils, use the trick based on looking for distro-specific version files instead as fall-back (same as what was done in the previous `install_deps.sh` bash script).
This commit is contained in:
parent
00f88babed
commit
c41841da3b
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -1630,22 +1631,43 @@ def get_distro(settings):
|
||||||
settings.logger.info(f"Distribution identifier forced by user to {settings.distro_id}.")
|
settings.logger.info(f"Distribution identifier forced by user to {settings.distro_id}.")
|
||||||
return settings.distro_id
|
return settings.distro_id
|
||||||
import platform
|
import platform
|
||||||
info = platform.freedesktop_os_release()
|
if hasattr(platform, "freedesktop_os_release"):
|
||||||
ids = [info["ID"]]
|
info = platform.freedesktop_os_release()
|
||||||
if "ID_LIKE" in info:
|
ids = [info["ID"]]
|
||||||
# ids are space separated and ordered by precedence.
|
if "ID_LIKE" in info:
|
||||||
ids.extend(info["ID_LIKE"].split())
|
# ids are space separated and ordered by precedence.
|
||||||
for distro_id in ids:
|
ids.extend(info["ID_LIKE"].split())
|
||||||
if distro_id in DISTRO_IDS_INSTALLERS:
|
for distro_id in ids:
|
||||||
settings.distro_id = distro_id
|
if distro_id in DISTRO_IDS_INSTALLERS:
|
||||||
return distro_id
|
settings.distro_id = distro_id
|
||||||
settings.logger.warning(f"Distribution IDs do not match any supported one by this script ({ids})")
|
return distro_id
|
||||||
|
settings.logger.warning(f"Distribution IDs do not match any supported one by this script ({ids})")
|
||||||
|
|
||||||
|
settings.logger.warning("A valid distribution ID could not be found using `platform.freedesktop_os_release`, "
|
||||||
|
"now trying a lower-level check for specific files")
|
||||||
|
if os.path.exists("/etc/debian_version"):
|
||||||
|
distro_id = DISTRO_ID_DEBIAN
|
||||||
|
elif os.path.exists("/etc/redhat-release"):
|
||||||
|
distro_id = DISTRO_ID_FEDORA
|
||||||
|
elif os.path.exists("/etc/SuSE-release"):
|
||||||
|
distro_id = DISTRO_ID_SUSE
|
||||||
|
elif os.path.exists("/etc/arch-release"):
|
||||||
|
distro_id = DISTRO_ID_ARCH
|
||||||
|
if distro_id in DISTRO_IDS_INSTALLERS:
|
||||||
|
settings.distro_id = distro_id
|
||||||
|
return distro_id
|
||||||
|
|
||||||
settings.distro_id = ...
|
settings.distro_id = ...
|
||||||
return ...
|
return ...
|
||||||
|
|
||||||
|
|
||||||
def get_distro_package_installer(settings):
|
def get_distro_package_installer(settings):
|
||||||
return DISTRO_IDS_INSTALLERS[get_distro(settings)](settings)
|
distro_id = get_distro(settings)
|
||||||
|
if distro_id is ...:
|
||||||
|
settings.logger.warning("No valid distribution ID found, please try to set it using the `--distro-id` option")
|
||||||
|
else:
|
||||||
|
settings.logger.info(f"Distribution identified as '{distro_id}'")
|
||||||
|
return DISTRO_IDS_INSTALLERS[distro_id](settings)
|
||||||
|
|
||||||
|
|
||||||
def argparse_create():
|
def argparse_create():
|
||||||
|
|
Loading…
Reference in New Issue