Ejemplo n.º 1
0
    def install_build_packages(cls, package_names: List[str]) -> List[str]:
        """Install packages on the host required to build.

        :param package_names: a list of package names to install.
        :type package_names: a list of strings.
        :return: a list with the packages installed and their versions.
        :rtype: list of strings.
        :raises snapcraft.repo.errors.BuildPackageNotFoundError:
            if one of the packages was not found.
        :raises snapcraft.repo.errors.PackageBrokenError:
            if dependencies for one of the packages cannot be resolved.
        :raises snapcraft.repo.errors.BuildPackagesNotInstalledError:
            if installing the packages on the host failed.
        """
        logger.debug(f"Requested build-packages: {sorted(package_names)!r}")

        # Make sure all packages are valid and remove already installed.
        with AptCache() as apt_cache:
            try:
                apt_cache.mark_packages(set(package_names))
            except errors.PackageNotFoundError as error:
                raise errors.BuildPackageNotFoundError(error.package_name)

            marked_packages = apt_cache.get_marked_packages()

            # TODO: this matches prior behavior, but the version is not
            # being passed along to apt-get install, even if prescribed
            # by the user.  We should specify it upon user request.
            install_packages = sorted([name for name, _ in marked_packages])

            # Install packages, if any.
            if install_packages:
                cls._install_packages(install_packages)

        return sorted([f"{name}={version}" for name, version in marked_packages])
Ejemplo n.º 2
0
    def _get_marked_packages(cls, package_names: List[str]) -> List[Tuple[str, str]]:
        with AptCache() as apt_cache:
            try:
                apt_cache.mark_packages(set(package_names))
            except errors.PackageNotFoundError as error:
                raise errors.BuildPackageNotFoundError(error.package_name)

            return apt_cache.get_marked_packages()