Account for multiple modules, and match arch

This commit is contained in:
Mustafa Gezen 2023-02-03 01:11:00 +01:00
parent ea2c37f66a
commit 9b60921a42
Signed by untrusted user who does not match committer: mustafa
GPG Key ID: DCDF010D946438C1

View File

@ -156,13 +156,12 @@ async def get_updateinfo(
# Add packages # Add packages
packages = ET.SubElement(update, "pkglist") packages = ET.SubElement(update, "pkglist")
# Create collection suffixes_to_skip = [
collection = ET.SubElement(packages, "collection") "-debuginfo",
collection_short = slugify(f"{product_name}-{repo}-rpms") "-debugsource",
collection.set("short", collection_short) "-debuginfo-common",
"-debugsource-common",
# Set short to name as well ]
ET.SubElement(collection, "name").text = collection_short
pkg_name_map = {} pkg_name_map = {}
for pkg in advisory.packages: for pkg in advisory.packages:
@ -174,26 +173,69 @@ async def get_updateinfo(
pkg_src_rpm = {} pkg_src_rpm = {}
for top_pkg in advisory.packages: for top_pkg in advisory.packages:
if top_pkg.package_name not in pkg_src_rpm: if top_pkg.package_name not in pkg_src_rpm:
top_nvra_no_epoch = EPOCH_RE.sub("", top_pkg.nevra)
top_nvra = NVRA_RE.search(top_nvra_no_epoch)
top_arch = top_nvra.group(4)
for pkg in pkg_name_map[top_pkg.package_name]: for pkg in pkg_name_map[top_pkg.package_name]:
nvra_no_epoch = EPOCH_RE.sub("", pkg.nevra) nvra_no_epoch = EPOCH_RE.sub("", pkg.nevra)
nvra = NVRA_RE.search(nvra_no_epoch) nvra = NVRA_RE.search(nvra_no_epoch)
if nvra: if nvra:
name = nvra.group(1) name = nvra.group(1)
arch = nvra.group(4) arch = nvra.group(4)
if pkg.package_name == name and top_arch == arch: if pkg.package_name == name and arch == "src":
src_rpm = nvra_no_epoch src_rpm = nvra_no_epoch
if not src_rpm.endswith(".rpm"): if not src_rpm.endswith(".rpm"):
src_rpm += ".rpm" src_rpm += ".rpm"
pkg_src_rpm[pkg.package_name] = src_rpm pkg_src_rpm[pkg.package_name] = src_rpm
# If we encounter modules, we need to add them to the collection later # Collection list, may be more than one if module RPMs are involved
modules = {} collections = {}
no_default_collection = False
default_collection_short = slugify(f"{product_name}-{repo}-rpms")
# Check if this is an actual module advisory, if so we need to split the
# collections, and module RPMs need to go into their own collection based on
# module name, while non-module RPMs go into the main collection (if any)
for pkg in advisory.packages: for pkg in advisory.packages:
if pkg.module_name:
collection_short = f"{default_collection_short}__{pkg.module_name}"
if collection_short not in collections:
collections[collection_short] = {
"packages": [],
"module_context": pkg.module_context,
"module_name": pkg.module_name,
"module_stream": pkg.module_stream,
"module_version": pkg.module_version,
}
no_default_collection = True
collections[collection_short]["packages"].append(pkg)
else:
if no_default_collection:
continue
if collection_short not in collections:
collections[collection_short] = {
"packages": [],
}
collections[collection_short]["packages"].append(pkg)
if no_default_collection and default_collection_short in collections:
del collections[default_collection_short]
for collection_short, info in collections.items():
# Create collection
collection = ET.Element("collection")
collection.set("short", collection_short)
# Set short to name as well
ET.SubElement(collection, "name").text = collection_short
if "module_name" in info:
module_element = ET.SubElement(collection, "module")
module_element.set("name", info["module_name"])
module_element.set("stream", info["module_stream"])
module_element.set("version", info["module_version"])
module_element.set("context", info["module_context"])
module_element.set("arch", product_arch)
added_pkg_count = 0
for pkg in info["packages"]:
if pkg.nevra.endswith(".src.rpm"): if pkg.nevra.endswith(".src.rpm"):
continue continue
@ -217,6 +259,16 @@ async def get_updateinfo(
if pkg.package_name not in pkg_src_rpm: if pkg.package_name not in pkg_src_rpm:
continue continue
if arch != product_arch:
continue
skip = False
for suffix in suffixes_to_skip:
if name.endswith(suffix):
skip = True
break
if skip:
continue
package = ET.SubElement(collection, "package") package = ET.SubElement(collection, "package")
package.set("name", name) package.set("name", name)
@ -235,25 +287,10 @@ async def get_updateinfo(
package, "sum", type=pkg.checksum_type package, "sum", type=pkg.checksum_type
).text = pkg.checksum ).text = pkg.checksum
# Check if module added_pkg_count += 1
if pkg.module_name:
modules[pkg.module_name] = {
"name": pkg.module_name,
"context": pkg.module_context,
"stream": pkg.module_stream,
"version": pkg.module_version,
"arch": product_arch,
}
# Add modules if added_pkg_count > 0:
for module in modules.values(): packages.append(collection)
module_element = ET.Element("module")
module_element.set("name", module["name"])
module_element.set("stream", module["stream"])
module_element.set("version", module["version"])
module_element.set("context", module["context"])
module_element.set("arch", module["arch"])
collection.insert(1, module_element)
ET.indent(tree) ET.indent(tree)
xml_str = ET.tostring(tree, encoding="unicode", method="xml") xml_str = ET.tostring(tree, encoding="unicode", method="xml")