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
packages = ET.SubElement(update, "pkglist")
# Create collection
collection = ET.SubElement(packages, "collection")
collection_short = slugify(f"{product_name}-{repo}-rpms")
collection.set("short", collection_short)
# Set short to name as well
ET.SubElement(collection, "name").text = collection_short
suffixes_to_skip = [
"-debuginfo",
"-debugsource",
"-debuginfo-common",
"-debugsource-common",
]
pkg_name_map = {}
for pkg in advisory.packages:
@ -174,26 +173,69 @@ async def get_updateinfo(
pkg_src_rpm = {}
for top_pkg in advisory.packages:
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]:
nvra_no_epoch = EPOCH_RE.sub("", pkg.nevra)
nvra = NVRA_RE.search(nvra_no_epoch)
if nvra:
name = nvra.group(1)
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
if not src_rpm.endswith(".rpm"):
src_rpm += ".rpm"
pkg_src_rpm[pkg.package_name] = src_rpm
# If we encounter modules, we need to add them to the collection later
modules = {}
# Collection list, may be more than one if module RPMs are involved
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:
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"):
continue
@ -217,6 +259,16 @@ async def get_updateinfo(
if pkg.package_name not in pkg_src_rpm:
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.set("name", name)
@ -235,25 +287,10 @@ async def get_updateinfo(
package, "sum", type=pkg.checksum_type
).text = pkg.checksum
# Check if module
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,
}
added_pkg_count += 1
# Add modules
for module in modules.values():
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)
if added_pkg_count > 0:
packages.append(collection)
ET.indent(tree)
xml_str = ET.tostring(tree, encoding="unicode", method="xml")