Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filtering based on comps file to build stage script #275

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion build_stage_repository
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import time
import hashlib
import sys
import tempfile
import dnf.comps
ehelms marked this conversation as resolved.
Show resolved Hide resolved


def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, dist, arch, source=False):
Expand All @@ -22,6 +23,7 @@ def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, d
os.mkdir(dest_folder)

repo_folder = f"{src_folder}/{dist}-{collection}-{version}-{arch}"
packages_to_include = packages_from_comps(comps(collection, version, dist))

if source:
files = glob.glob(repo_folder + f"/**/*.src.rpm")
Expand All @@ -30,17 +32,50 @@ def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, d

for file in files:
file_name = os.path.basename(file)
shutil.move(file, os.path.join(dest_folder, file_name))
rpm_name = get_rpm_name(file)

if rpm_name in packages_to_include:
shutil.move(file, os.path.join(dest_folder, file_name))

shutil.rmtree(src_folder)


def get_rpm_name(rpm):
command = [
'rpmquery',
'--nosignature',
'--queryformat',
'%{name}',
'--package',
rpm
]

return check_output(command, universal_newlines=True)


def modulemd_yaml(collection, version):
branch = 'develop' if version == 'nightly' else version
path, headers = urlretrieve(f"https://raw.githubusercontent.com/theforeman/foreman-packaging/rpm/{branch}/modulemd/modulemd-{collection}-el8.yaml")
return path


def comps(collection, version, dist):
branch = 'develop' if version == 'nightly' else version

if collection == 'foreman-katello':
name = 'katello'
elif collection == 'foreman-candlepin':
name = 'katello-candlepin'
else:
name = collection

if collection == 'foreman-client' and dist == 'el7':
dist = 'rhel7'

path, headers = urlretrieve(f"https://raw.githubusercontent.com/theforeman/foreman-packaging/rpm/{branch}/comps/comps-{name}-{dist}.xml")
return path


def generate_modulemd_version(version):
if version == 'nightly':
modulemd_version_prefix = '9999'
Expand Down Expand Up @@ -120,6 +155,23 @@ def sync_copr_repository(collection, version, target_dir, dist, arch, source=Fal
check_output(cmd)


def packages_from_comps(comps):
dnf_comps = dnf.comps.Comps()

try:
dnf_comps._add_from_xml_filename(comps)
except libcomps.ParserError:
errors = comps.get_last_errors()
raise CompsError(' '.join(errors))

packages = set()
for group in dnf_comps.groups:
for package in group.default_packages:
packages.add(package.name)

return packages


def main():
try:
collection = sys.argv[1]
Expand Down