示例#1
0
def gather_affected_targets(session: ClientSession,
                            tagnames: Iterable[TagSpec]) -> List[TargetInfo]:
    """
    Returns the list of target info dicts representing the targets
    which inherit any of the given named tags. That is to say, the
    targets whose build tags are children of the named tags.

    This list allows us to gauge what build configurations would be
    impacted by changes to the given tags.

    :param tagnames: List of tag names

    :raises NoSuchTag: if any of the names do not resolve to a tag
      info

    :since: 1.0
    """

    tags = [as_taginfo(session, t) for t in set(tagnames)]

    ifn = lambda tag: session.getFullInheritance(tag['id'], reverse=True)
    loaded = bulk_load(session, ifn, tags)
    parents = filter(None, loaded.values())

    tagids = set(chain(*((ch['tag_id'] for ch in ti) for ti in parents)))
    tagids.update(tag['id'] for tag in tags)

    tfn = lambda ti: session.getBuildTargets(buildTagID=ti)
    loaded = bulk_load(session, tfn, tagids)
    targets = chain(*filter(None, loaded.values()))

    return list(targets)
示例#2
0
def collect_tag_extras(session: ClientSession,
                       tag: TagSpec,
                       prefix: Optional[str] = None) -> DecoratedTagExtras:
    """
    Similar to session.getBuildConfig but with additional information
    recording which tag in the inheritance supplied the setting.

    Returns an dict of tag extra settings, keyed by the name of the
    setting. Each setting is represented as its own dict composed of
    the following keys:

    * name - the extra setting key
    * value - the extra setting value
    * blocked - whether the setting represents a block
    * tag_name - the name of the tag this setting came from
    * tag_id - the ID of the tag this setting came from

    :param session: an active koji client session

    :param tag: koji tag info dict, or tag name

    :param prefix: Extra name prefix to select for. If set, only tag
      extra fields whose key starts with the prefix string will be
      collected. Default, collect all.

    :since: 1.0
    """

    # this borrows heavily from the hub implementation of
    # getBuildConfig, but gives us a chance to record what tag in the
    # inheritance that the setting is coming from

    taginfo = as_taginfo(session, tag)
    found = convert_tag_extras(taginfo, prefix=prefix)

    inher = session.getFullInheritance(taginfo["id"])
    tids = (tag["parent_id"] for tag in inher if not tag["noconfig"])
    parents = bulk_load_tags(session, tids)

    for ptag in parents.values():
        # mix the extras into existing found results. note: we're not
        # checking for faults, because we got this list of tag IDs
        # straight from koji itself, but there could be some kind of
        # race condition from this.
        convert_tag_extras(ptag, into=found, prefix=prefix)

    return found