예제 #1
0
def annotate_snapcraft(data, parts_dir: str):
    manifest = OrderedDict()  # type: Dict[str, Any]
    manifest["snapcraft-version"] = snapcraft._get_version()

    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
    for field in ("build-packages", "build-snaps"):
        manifest[field] = get_global_state().assets.get(field, [])
    for part in data["parts"]:
        state_dir = os.path.join(parts_dir, part, "state")
        pull_state = get_state(state_dir, steps.PULL)
        manifest["parts"][part]["build-packages"] = pull_state.assets.get(
            "build-packages", [])
        manifest["parts"][part]["stage-packages"] = 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)
    return manifest
예제 #2
0
def annotate_snapcraft(project: "Project", data: Dict[str,
                                                      Any]) -> Dict[str, Any]:
    manifest = OrderedDict()  # type: Dict[str, Any]
    manifest["snapcraft-version"] = snapcraft._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
예제 #3
0
def annotate_snapcraft(data, parts_dir: str):
    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
        data['image-info'] = image_info_dict
    for field in ('build-packages', 'build-snaps'):
        data[field] = get_global_state().assets.get(field, [])
    for part in data['parts']:
        state_dir = os.path.join(parts_dir, part, 'state')
        pull_state = get_state(state_dir, 'pull')
        data['parts'][part]['build-packages'] = (pull_state.assets.get(
            'build-packages', []))
        data['parts'][part]['stage-packages'] = (pull_state.assets.get(
            'stage-packages', []))
        source_details = pull_state.assets.get('source-details', {})
        if source_details:
            data['parts'][part].update(source_details)
        build_state = get_state(state_dir, 'build')
        data['parts'][part].update(build_state.assets)
    return data