Beispiel #1
0
def get_user_agent(platform: str = sys.platform) -> str:
    arch = project.Project().deb_arch
    testing = "(testing) " if _is_ci_env() else ""

    if platform == "linux":
        os_platform = _get_linux_release(os_release.OsRelease())
    else:
        os_platform = platform.title()

    return f"snapcraft/{snapcraft_legacy.__version__} {testing}{os_platform} ({arch})"
Beispiel #2
0
    def test_no_name(self):
        release = os_release.OsRelease(os_release_file=self._write_os_release(
            dedent("""\
                ID=arch
                PRETTY_NAME="Arch Linux"
                ID_LIKE=archlinux
                VERSION_ID="foo"
                VERSION_CODENAME="bar"
            """)))

        self.assertRaises(errors.OsReleaseNameError, release.name)
Beispiel #3
0
    def test_no_version_codename_or_version_id(self):
        release = os_release.OsRelease(os_release_file=self._write_os_release(
            dedent("""\
                NAME="Ubuntu"
                ID=ubuntu
                ID_LIKE=debian
                PRETTY_NAME="Ubuntu 16.04.3 LTS"
            """)))

        self.assertRaises(errors.OsReleaseCodenameError,
                          release.version_codename)
Beispiel #4
0
    def test_no_version_id(self):
        release = os_release.OsRelease(os_release_file=self._write_os_release(
            dedent("""\
                NAME="Arch Linux"
                ID=arch
                PRETTY_NAME="Arch Linux"
                ID_LIKE=archlinux
                VERSION_CODENAME="bar"
            """)))

        self.assertRaises(errors.OsReleaseVersionIdError, release.version_id)
Beispiel #5
0
 def get_required_package_repositories(cls) -> List[PackageRepository]:
     codename = os_release.OsRelease().version_codename()
     return [
         PackageRepositoryApt(
             formats=["deb"],
             components=["main"],
             key_id="C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654",
             url="http://packages.ros.org/ros2/ubuntu",
             suites=[codename],
         )
     ]
Beispiel #6
0
    def test_no_version_codename(self):
        """Test that version codename can also come from VERSION_ID"""
        release = os_release.OsRelease(os_release_file=self._write_os_release(
            dedent("""\
                NAME="Ubuntu"
                VERSION="14.04.5 LTS, Trusty Tahr"
                ID=ubuntu
                ID_LIKE=debian
                PRETTY_NAME="Ubuntu 14.04.5 LTS"
                VERSION_ID="14.04"
            """)))

        self.assertThat(release.version_codename(), Equals("trusty"))
Beispiel #7
0
def annotate_snapcraft(project: "Project", data: Dict[str, Any]) -> Dict[str, Any]:
    manifest = OrderedDict()  # type: Dict[str, Any]
    manifest["snapcraft-version"] = snapcraft_legacy._get_version()
    manifest["snapcraft-started-at"] = project._get_start_time().isoformat() + "Z"

    release = os_release.OsRelease()
    with contextlib.suppress(errors.OsReleaseIdError):
        manifest["snapcraft-os-release-id"] = release.id()
    with contextlib.suppress(errors.OsReleaseVersionIdError):
        manifest["snapcraft-os-release-version-id"] = release.version_id()

    for k, v in data.items():
        manifest[k] = v
    image_info = os.environ.get("SNAPCRAFT_IMAGE_INFO")
    if image_info:
        try:
            image_info_dict = json.loads(image_info)
        except json.decoder.JSONDecodeError as exception:
            raise errors.InvalidContainerImageInfoError(image_info) from exception
        manifest["image-info"] = image_info_dict

    global_state = GlobalState.load(filepath=project._get_global_state_file_path())
    manifest["build-packages"] = sorted(global_state.get_build_packages())
    manifest["build-snaps"] = sorted(global_state.get_build_snaps())

    for part in data["parts"]:
        state_dir = os.path.join(project.parts_dir, part, "state")
        pull_state = get_state(state_dir, steps.PULL)
        manifest["parts"][part]["build-packages"] = sorted(
            pull_state.assets.get("build-packages", [])
        )
        manifest["parts"][part]["stage-packages"] = sorted(
            pull_state.assets.get("stage-packages", [])
        )
        source_details = pull_state.assets.get("source-details", {})
        if source_details:
            manifest["parts"][part].update(source_details)
        build_state = get_state(state_dir, steps.BUILD)
        manifest["parts"][part].update(build_state.assets)

    # Assemble all primed stage packages into a single list...
    primed_stage_packages: Set[str] = set()
    for part in data["parts"]:
        state_dir = os.path.join(project.parts_dir, part, "state")
        prime_state = get_state(state_dir, steps.PRIME)
        primed_stage_packages |= prime_state.primed_stage_packages
    manifest["primed-stage-packages"] = sorted(primed_stage_packages)

    return manifest
Beispiel #8
0
    def test_blank_lines(self):
        release = os_release.OsRelease(os_release_file=self._write_os_release(
            dedent("""\
                NAME="Arch Linux"

                PRETTY_NAME="Arch Linux"
                ID=arch
                ID_LIKE=archlinux
                VERSION_ID="foo"
                VERSION_CODENAME="bar"

            """)))

        self.assertThat(release.id(), Equals("arch"))
        self.assertThat(release.name(), Equals("Arch Linux"))
        self.assertThat(release.version_id(), Equals("foo"))
        self.assertThat(release.version_codename(), Equals("bar"))
Beispiel #9
0
    def _setUp(self):
        super()._setUp()

        with open("os-release", "w") as release_file:
            if self._name is not None:
                print(f'NAME="{self._name}"', file=release_file)

            print(
                dedent(
                    """\
                VERSION="18.04.3 LTS (Xenial Xerus)"
                ID_LIKE=debian
                PRETTY_NAME="Ubuntu 18.04.3 LTS"
                HOME_URL="http://www.ubuntu.com/"
                SUPPORT_URL="http://help.ubuntu.com/"
                BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
                UBUNTU_CODENAME=bionic"""
                ),
                file=release_file,
            )

            if self._id is not None:
                print("ID={}".format(self._id), file=release_file)
            if self._version_id is not None:
                print('VERSION_ID="{}"'.format(self._version_id), file=release_file)
            if self._version_codename is not None:
                print(
                    "VERSION_CODENAME={}".format(self._version_codename),
                    file=release_file,
                )

        release = os_release.OsRelease(os_release_file="os-release")

        def _create_os_release(*args, **kwargs):
            return release

        patcher = mock.patch(
            "snapcraft_legacy.internal.os_release.OsRelease", wraps=_create_os_release
        )
        patcher.start()
        self.addCleanup(patcher.stop)
Beispiel #10
0
    def is_host_compatible_with_base(self, base: str) -> bool:
        """Determines if the host is compatible with the GLIBC of the base.

        The system should warn early on when building using a host that does
        not match the intended base, this mechanism here enables additional
        logic when that is ignored to determine built projects will actually
        run.

        :param str base: the base core snap to search for linker.
        :returns: True if there are no GLIBC incompatibilities with the chosen
                  build host, else it returns False.
        :rtype: bool
        """
        try:
            codename = os_release.OsRelease().version_codename()
        except errors.OsReleaseCodenameError:
            return False

        logger.debug("Running on {!r}".format(codename))

        # TODO: we should get rid of this check.
        return _HOST_CODENAME_FOR_BASE.get(base) == codename
Beispiel #11
0
    def _install_sources_ppa(
            self, *,
            package_repo: package_repository.PackageRepositoryAptPpa) -> bool:
        """Install PPA formatted repository.

        Create a sources list config by:
        - Looking up the codename of the host OS and using it as the "suites"
          entry.
        - Formulate deb URL to point to PPA.
        - Enable only "deb" formats.

        :returns: True if source configuration was changed.
        """
        owner, name = apt_ppa.split_ppa_parts(ppa=package_repo.ppa)
        codename = os_release.OsRelease().version_codename()

        return self._install_sources(
            components=["main"],
            formats=["deb"],
            name=f"ppa-{owner}_{name}",
            suites=[codename],
            url=f"http://ppa.launchpad.net/{owner}/{name}/ubuntu",
        )