# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-## Copyright 2017-2023 Canonical Ltd.## This program is free software; you can redistribute it and/or# modify it under the terms of the GNU Lesser General Public# License version 3 as published by the Free Software Foundation.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# Lesser General Public License for more details.## You should have received a copy of the GNU Lesser General Public License# along with this program. If not, see <http://www.gnu.org/licenses/>."""Helpers to determine the repository for the platform."""fromcraft_partsimporterrorsfromcraft_parts.utilsimportos_utils_DEB_BASED_PLATFORM=["ubuntu","debian","elementary OS","elementary","neon"]_YUM_BASED_PLATFORM=["centos"]_DNF_BASED_PLATFORM=["almalinux"]def_check(distro:str|None,platform_distros:list[str])->bool:"""Check if `distro` is included in the specified platform distros. If the indicated `distro` is None it will be retrieved from OsRelease or return "unknown" on error. """ifnotdistro:try:distro=os_utils.OsRelease().id()excepterrors.OsReleaseIdError:distro="unknown"returndistroinplatform_distros
[docs]defis_deb_based(distro:str|None=None)->bool:"""Verify the distribution packaging system. :param distro: The distribution name. :return: Whether the distribution uses .deb packages. """return_check(distro,_DEB_BASED_PLATFORM)
[docs]defis_yum_based(distro:str|None=None)->bool:"""Verify the distribution packaging system. :param distro: The distribution name. :return: Whether the distribution handles packages through YUM. """return_check(distro,_YUM_BASED_PLATFORM)
[docs]defis_dnf_based(distro:str|None=None)->bool:"""Verify the distribution packaging system. :param distro: The distribution name. :return: Whether the distribution handles packages through DNF. """return_check(distro,_DNF_BASED_PLATFORM)