Esempio n. 1
0
    def latest_builds(self,
                      session: ClientSession,
                      tag_id: int,
                      inherit: bool = True) -> List[BuildInfo]:
        """
        a caching wrapper for ``session.getLatestBuilds``
        """

        cache = self._mixin_cache("latest_builds")

        key = (tag_id, inherit)
        found = cache.get(key)

        if found is None:
            found = session.getLatestBuilds(tag_id)
            cache[key] = found

        return found
Esempio n. 2
0
def gather_latest_image_archives(
        session: ClientSession,
        tagname: TagSpec,
        inherit: bool = True,
        path: Optional[PathSpec] = None) -> List[DecoratedArchiveInfo]:
    """
    :param session: an active koji client session

    :param tagname: Name of the tag to gather archives from

    :param inherit: Follow tag inheritance, default True

    :param path: Path prefix for archive filepaths

    :raises NoSuchTag: if the specified tag doesn't exist
    """

    tag = as_taginfo(session, tagname)
    path = as_pathinfo(path)

    found = []

    # we cannot use listTaggedArchives here, because it only accepts types
    # of win and maven. I should submit a patch to upstream.

    if inherit:
        builds = session.getLatestBuilds(tag['id'], type="image")
    else:
        builds = session.listTagged(tag['id'], latest=True, type="image")

    for bld in builds:
        build_path = path.imagebuild(bld)
        loaded = session.listArchives(buildID=bld["id"], type="image")
        archives = cast(List[DecoratedArchiveInfo], loaded)
        for archive in archives:
            archive["filepath"] = join(build_path, archive["filename"])
        found.extend(archives)

    return found
Esempio n. 3
0
def gather_latest_archives(
        session: ClientSession,
        tagname: TagSpec,
        btype: Optional[str] = None,
        rpmkeys: Sequence[str] = (),
        inherit: bool = True,
        path: Optional[PathSpec] = None) -> List[DecoratedArchiveInfo]:
    """
    Gather the latest archives from a tag heirarchy. Rules for what
    constitutes "latest" may change slightly depending on the archive
    types -- specifically maven.

    :param session: an active koji client session

    :param tagname: Name of the tag to gather archives from

    :param btype: Name of the BType to gather. Default, gather all

    :param rpmkeys: List of RPM signatures to filter by. Only used when
        fetching type of rpm or None (all).

    :param inherit: Follow tag inheritance, default True

    :param path: Path prefix for archive filepaths.

    :raises NoSuchTag: if specified tag doesn't exist
    """

    # we'll cheat a bit and use as_taginfo to verify that the tag
    # exists -- it will raise a NoSuchTag for us if necessary. We
    # aren't doing any such checking in the lower-level per-type
    # gather functions.
    tag = as_taginfo(session, tagname)

    known_types = ("rpm", "maven", "win", "image")
    found: List[DecoratedArchiveInfo] = []

    # the known types have additional metadata when queried, and have
    # pre-defined path structures. We'll be querying those directly
    # first.

    path = as_pathinfo(path)

    if btype in (None, "rpm"):
        found.extend(gather_latest_rpms(session, tag, rpmkeys,
                                        inherit, path))  # type: ignore

    if btype in (None, "maven"):
        found.extend(gather_latest_maven_archives(session, tag,
                                                  inherit, path))

    if btype in (None, "win"):
        found.extend(gather_latest_win_archives(session, tag,
                                                inherit, path))

    if btype in (None, "image"):
        found.extend(gather_latest_image_archives(session, tag,
                                                  inherit, path))

    if btype in known_types:
        return cast(List[DecoratedArchiveInfo], found)

    if btype is None:
        # listTaggedArchives is very convenient, but only works with
        # win, maven, and None
        archives, lbuilds = session.listTaggedArchives(tag['id'],
                                                       inherit=inherit,
                                                       latest=True,
                                                       type=None)

        # convert builds to an id:binfo mapping
        builds = {bld["id"]: bld for bld in lbuilds}

        for archive in archives:
            abtype = archive["btype"]
            if abtype in known_types:
                # filter out any of the types we would have queried on
                # their own earlier. Unfortunately there doesn't seem
                # to be a way to get around throwing away this
                # duplicate data for cases where btype is None
                continue

            # determine the path specific to this build and the
            # discovered archive btype
            bld = builds[archive["build_id"]]
            build_path = path.typedir(bld, abtype)

            # build an archive filepath from that
            decor = cast(DecoratedArchiveInfo, archive)
            decor["filepath"] = join(build_path, archive["filename"])
            found.append(decor)

    else:
        # btype is not one of the known ones, and it's also not None.
        if inherit:
            ibuilds = session.getLatestBuilds(tag['id'], type=btype)
        else:
            ibuilds = session.listTagged(tag['id'], latest=True, type=btype)

        for bld in ibuilds:
            build_path = path.typedir(bld, btype)
            archives = session.listArchives(buildID=bld["id"], type=btype)
            for archive in archives:
                decor = cast(DecoratedArchiveInfo, archive)
                decor["filepath"] = join(build_path, archive["filename"])
                found.append(decor)

    return cast(List[DecoratedArchiveInfo], found)