Пример #1
0
    def dest_get_archs(trees, src_arch, names, cache_entry, version=None, overrides=None):
        '''Return a list of arches that this package/arch combination ships on.'''

        if trees is None:
            return dict((name, src_arch) for name in names)

        query = models.Trees.query.with_entities(models.Trees.arch, models.Packages.name).join(models.Trees.packages).filter(
            models.Packages.arch == src_arch, models.Packages.name.in_(names),
            models.Trees.id.in_(trees), models.Trees.imported == 1)
        if version:
            query = query.filter(models.Packages.version == version)

        ret = {}
        for arow in query.all():
            ret.setdefault(arow.name, {}).setdefault(arow.arch, 1)

        for name in names:
            # use cached map entry if there are no records from treetables
            if koji.is_debuginfo(name) and not ret.get(name, {}):
                ret[name] = copy.deepcopy(cache_entry)

            if overrides and name in overrides and src_arch in overrides[name] and not version:
                for tree_arch, include in overrides[name][src_arch].items():
                    if include:
                        ret.setdefault(name, {}).setdefault(tree_arch, 1)
                    elif name in ret and tree_arch in ret[name]:
                        del ret[name][tree_arch]
        return ret
Пример #2
0
    def dest_get_archs(compose_dbh, trees, src_arch, names, cache_entry, version=None, overrides=None):
        '''Return a list of arches that this package/arch combination ships on.'''

        if trees is None:
            return dict((name, src_arch) for name in names)

        dbc = compose_dbh.cursor()
        qry = "SELECT DISTINCT trees.arch, packages.name FROM trees, packages, tree_packages WHERE trees.imported = 1 and trees.id = tree_packages.trees_id AND packages.id = tree_packages.packages_id AND packages.arch = %s AND packages.name = ANY(%s) AND trees.id = ANY(%s)"
        qargs = [src_arch, names, trees]
        if version:
            qry += " AND packages.version = %s"
            qargs.append(version)
        Products.execute_query(dbc, qry, qargs)
        ret = {}
        while 1:
            arow = dbc.fetchone()
            if not arow:
                break
            ret.setdefault(arow[1], {}).setdefault(arow[0], 1)
        for name in names:
            # use cached map entry if there are no records from treetables
            if koji.is_debuginfo(name) and not ret.get(name, {}):
                ret[name] = cache_entry

            if overrides and overrides.has_key(name) and overrides[name].has_key(src_arch) and not version:
                for tree_arch, include in overrides[name][src_arch].items():
                    if include:
                        ret.setdefault(name, {}).setdefault(tree_arch, 1)
                    elif ret.has_key(tree_arch):
                        del ret[name][tree_arch]
        return ret
Пример #3
0
    def dest_get_archs(compose_dbh,
                       trees,
                       src_arch,
                       names,
                       cache_entry,
                       version=None,
                       overrides=None):
        '''Return a list of arches that this package/arch combination ships on.'''

        if trees is None:
            return dict((name, src_arch) for name in names)

        dbc = compose_dbh.cursor()
        qry = """
            SELECT DISTINCT trees.arch, packages.name
            FROM trees, packages, tree_packages
            WHERE trees.imported = 1 and trees.id = tree_packages.trees_id
            AND packages.id = tree_packages.packages_id
            AND packages.arch = %(arch)s
            """

        if pgdb.version.startswith('4'):
            # backwards compatibility with pygresql 4 in eng-rhel-7
            qry += """
                AND packages.name IN %(names)s
                AND trees.id IN %(trees)s
                """
        else:
            qry += """
                AND packages.name = ANY(%(names)s)
                AND trees.id = ANY(%(trees)s)
                """

        qargs = dict(arch=src_arch, names=names, trees=trees)
        if version:
            qry += " AND packages.version = %(version)s"
            qargs['version'] = version
        Products.execute_query(dbc, qry, **qargs)
        ret = {}
        while 1:
            arow = dbc.fetchone()
            if not arow:
                break
            ret.setdefault(arow[1], {}).setdefault(arow[0], 1)
        for name in names:
            # use cached map entry if there are no records from treetables
            if koji.is_debuginfo(name) and not ret.get(name, {}):
                ret[name] = cache_entry

            if overrides and overrides.has_key(name) and overrides[
                    name].has_key(src_arch) and not version:
                for tree_arch, include in overrides[name][src_arch].items():
                    if include:
                        ret.setdefault(name, {}).setdefault(tree_arch, 1)
                    elif name in ret and tree_arch in ret[name]:
                        del ret[name][tree_arch]
        return ret
Пример #4
0
def getProductListings(productLabel, buildInfo):
    """
    Get a map of which variants of the given product included packages built
    by the given build, and which arches each variant included.
    """
    session = get_koji_session()
    build = get_build(buildInfo, session)

    rpms = session.listRPMs(buildID=build['id'])
    if not rpms:
        raise ProductListingsNotFoundError("Could not find any RPMs for build: %s" % buildInfo)

    # sort rpms, so first part of list consists of sorted 'normal' rpms and
    # second part are sorted debuginfos
    debuginfos = [x for x in rpms if '-debuginfo' in x['nvr']]
    base_rpms = [x for x in rpms if '-debuginfo' not in x['nvr']]
    rpms = sorted(base_rpms, key=lambda x: x['nvr']) + sorted(debuginfos, key=lambda x: x['nvr'])
    srpm = "%(package_name)s-%(version)s-%(release)s.src.rpm" % build

    prodinfo = Products.get_product_info(productLabel)
    version, variants = prodinfo

    listings = {}
    match_version = Products.get_match_versions(productLabel)
    for variant in variants:
        if variant is None:
            # dict keys must be a string
            variant = ''
        treelist = Products.precalc_treelist(productLabel, version, variant)
        if not treelist:
            continue
        overrides = Products.get_overrides(productLabel, version, variant)
        cache_map = {}
        for rpm in rpms:
            if rpm['name'] in match_version:
                rpm_version = rpm['version']
            else:
                rpm_version = None

        # without debuginfos
        rpms_nondebug = [rpm for rpm in rpms if not koji.is_debuginfo(rpm['name'])]
        d = {}
        all_archs = set([rpm['arch'] for rpm in rpms_nondebug])
        for arch in all_archs:
            d[arch] = Products.dest_get_archs(
                treelist,
                arch, [rpm['name'] for rpm in rpms_nondebug if rpm['arch'] == arch],
                cache_map.get(srpm, {}).get(arch, {}),
                rpm_version, overrides,)

        for rpm in rpms_nondebug:
            dest_archs = d[rpm['arch']].get(rpm['name'], {}).keys()
            if rpm['arch'] != 'src':
                cache_map.setdefault(srpm, {})
                cache_map[srpm].setdefault(rpm['arch'], {})
                for x in dest_archs:
                    cache_map[srpm][rpm['arch']][x] = 1
            for dest_arch in dest_archs:
                listings.setdefault(variant, {}).setdefault(rpm['nvr'], {}).setdefault(rpm['arch'], []).append(dest_arch)

        # debuginfo only
        rpms_debug = [rpm for rpm in rpms if koji.is_debuginfo(rpm['name'])]
        d = {}
        all_archs = set([rpm['arch'] for rpm in rpms_debug])
        for arch in all_archs:
            d[arch] = Products.dest_get_archs(
                treelist,
                arch, [rpm['name'] for rpm in rpms_debug if rpm['arch'] == arch],
                cache_map.get(srpm, {}).get(arch, {}),
                rpm_version, overrides,)

        for rpm in rpms_debug:
            dest_archs = d[rpm['arch']].get(rpm['name'], {}).keys()
            if rpm['arch'] != 'src':
                cache_map.setdefault(srpm, {})
                cache_map[srpm].setdefault(rpm['arch'], {})
                for x in dest_archs:
                    cache_map[srpm][rpm['arch']][x] = 1
            for dest_arch in dest_archs:
                listings.setdefault(variant, {}).setdefault(rpm['nvr'], {}).setdefault(rpm['arch'], []).append(dest_arch)

        for variant in list(listings.keys()):
            nvrs = list(listings[variant].keys())
            # BREW-260: Read allow_src_only flag for the product/version
            allow_src_only = Products.get_srconly_flag(productLabel, version)
            if len(nvrs) == 1:
                maps = list(listings[variant][nvrs[0]].keys())
                # BREW-260: check for allow_src_only flag added
                if len(maps) == 1 and maps[0] == 'src' and not allow_src_only:
                    del listings[variant]
    return listings
Пример #5
0
def getProductListings(productLabel, buildInfo):
    """
    Get a map of which variants of the given product included packages built
    by the given build, and which arches each variant included.
    """
    compose_dbh = Products.compose_get_dbh()

    #XXX - need access to hub kojihub functions
    conf = koji.read_config('brew')
    hub = conf['server']
    session = koji.ClientSession(hub, {})

    build = session.getBuild(buildInfo, strict=True)
    sys.stderr.write("%r" % build)
    sys.stderr.flush()
    rpms = session.listRPMs(buildID=build['id'])
    if not rpms:
        raise koji.GenericError("Could not find any RPMs for build: %s" %
                                buildInfo)

    # sort rpms, so first part of list consists of sorted 'normal' rpms and
    # second part are sorted debuginfos
    debuginfos = [x for x in rpms if '-debuginfo' in x['nvr']]
    base_rpms = [x for x in rpms if '-debuginfo' not in x['nvr']]
    rpms = sorted(base_rpms, key=lambda x: x['nvr']) + sorted(
        debuginfos, key=lambda x: x['nvr'])
    srpm = "%(package_name)s-%(version)s-%(release)s.src.rpm" % build

    prodinfo = Products.get_product_info(compose_dbh, productLabel)
    if not prodinfo:
        # no product with the given label exists
        raise koji.GenericError("Could not find a product with label: %s" %
                                productLabel)
    version, variants = prodinfo

    listings = {}
    match_version = Products.get_match_versions(compose_dbh, productLabel)
    for variant in variants:
        if variant == None:
            # dict keys must be a string
            variant = ''
        treelist = Products.precalc_treelist(compose_dbh, productLabel,
                                             version, variant)
        if not treelist:
            continue
        overrides = Products.get_overrides(compose_dbh, productLabel, version,
                                           variant)
        cache_map = {}
        for rpm in rpms:
            if rpm['name'] in match_version:
                rpm_version = rpm['version']
            else:
                rpm_version = None

        # without debuginfos
        rpms_nondebug = [
            rpm for rpm in rpms if not koji.is_debuginfo(rpm['name'])
        ]
        d = {}
        all_archs = set([rpm['arch'] for rpm in rpms_nondebug])
        for arch in all_archs:
            d[arch] = Products.dest_get_archs(
                compose_dbh,
                treelist,
                arch,
                [rpm['name'] for rpm in rpms_nondebug if rpm['arch'] == arch],
                cache_map.get(srpm, {}).get(arch, {}),
                rpm_version,
                overrides,
            )

        for rpm in rpms_nondebug:
            dest_archs = d[rpm['arch']].get(rpm['name'], {}).keys()
            if rpm['arch'] != 'src':
                cache_map.setdefault(srpm, {})
                cache_map[srpm].setdefault(rpm['arch'], {})
                for x in dest_archs:
                    cache_map[srpm][rpm['arch']][x] = 1
            for dest_arch in dest_archs:
                listings.setdefault(variant,
                                    {}).setdefault(rpm['nvr'], {}).setdefault(
                                        rpm['arch'], []).append(dest_arch)

        # debuginfo only
        rpms_debug = [rpm for rpm in rpms if koji.is_debuginfo(rpm['name'])]
        d = {}
        all_archs = set([rpm['arch'] for rpm in rpms_debug])
        for arch in all_archs:
            d[arch] = Products.dest_get_archs(
                compose_dbh,
                treelist,
                arch,
                [rpm['name'] for rpm in rpms_debug if rpm['arch'] == arch],
                cache_map.get(srpm, {}).get(arch, {}),
                rpm_version,
                overrides,
            )

        for rpm in rpms_debug:
            dest_archs = d[rpm['arch']].get(rpm['name'], {}).keys()
            if rpm['arch'] != 'src':
                cache_map.setdefault(srpm, {})
                cache_map[srpm].setdefault(rpm['arch'], {})
                for x in dest_archs:
                    cache_map[srpm][rpm['arch']][x] = 1
            for dest_arch in dest_archs:
                listings.setdefault(variant,
                                    {}).setdefault(rpm['nvr'], {}).setdefault(
                                        rpm['arch'], []).append(dest_arch)

        for variant in listings.keys():
            nvrs = listings[variant].keys()
            #BREW-260: Read allow_src_only flag for the product/version
            allow_src_only = Products.get_srconly_flag(compose_dbh,
                                                       productLabel, version)
            if len(nvrs) == 1:
                maps = listings[variant][nvrs[0]].keys()
                #BREW-260: check for allow_src_only flag added
                if len(maps) == 1 and maps[0] == 'src' and not allow_src_only:
                    del listings[variant]
    return listings