def _get_package_manager(cfg): """Talk to the target host and determine the package manager. Return "dnf" or "yum" if the package manager appears to be one of those. :raises pulp_smash.exceptions.NoKnownPackageManagerError: If unable to find any valid package manager on the target host. """ hostname = urlsplit(cfg.get_base_url()).hostname with contextlib.suppress(KeyError): return _PACKAGE_MANAGERS[hostname] client = Client(cfg, echo_handler) commands_managers = ( (("which", "dnf"), "dnf"), (("which", "yum"), "yum"), ) for cmd, pkg_mgr in commands_managers: if client.run(cmd, sudo=True).returncode == 0: _PACKAGE_MANAGERS[hostname] = pkg_mgr return pkg_mgr raise exceptions.NoKnownPackageManagerError( "Unable to determine the package manager used by {}. It does not " "appear to be any of {}.".format( hostname, {pkg_mgr for _, pkg_mgr in commands_managers}))
def _get_package_manager(cfg): """Talk to the target host and determine the package manager. Return "dnf" or "yum" if the package manager appears to be one of those. Raise an exception otherwise. """ hostname = urlsplit(cfg.get_base_url()).hostname try: return _PACKAGE_MANAGERS[hostname] except KeyError: pass client = Client(cfg, echo_handler) commands_managers = ( (('which', 'dnf'), 'dnf'), (('which', 'yum'), 'yum'), ) for cmd, pkg_mgr in commands_managers: if client.run(cmd).returncode == 0: _PACKAGE_MANAGERS[hostname] = pkg_mgr return pkg_mgr raise exceptions.NoKnownPackageManagerError( 'Unable to determine the package manager used by {}. It does not ' 'appear to be any of {}.'.format( hostname, {pkg_mgr for _, pkg_mgr in commands_managers}))