diff --git a/build_stage_repository b/build_stage_repository index 3fecc3f..85958d1 100755 --- a/build_stage_repository +++ b/build_stage_repository @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from subprocess import check_output, STDOUT, CalledProcessError +from urllib.request import urlretrieve import os import yaml import glob @@ -8,9 +9,10 @@ import shutil import time import hashlib import sys +import tempfile -def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, source=False): +def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, dist, source=False): if source: print(f"Moving {collection} Source RPMs from Copr directory to stage repository") else: @@ -19,7 +21,7 @@ def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, s if not os.path.exists(dest_folder): os.mkdir(dest_folder) - repo_folder = f"{src_folder}/el8-{collection}-{version}" + repo_folder = f"{src_folder}/{dist}-{collection}-{version}" if source: files = glob.glob(repo_folder + f"/**/*.src.rpm") @@ -34,7 +36,8 @@ def move_rpms_from_copr_to_stage(collection, version, src_folder, dest_folder, s def modulemd_yaml(collection): - return f"modulemd/modulemd-{collection}-el8.yaml" + path, headers = urlretrieve(f"https://raw.githubusercontent.com/theforeman/foreman-packaging/rpm/develop/modulemd/modulemd-{collection}-el8.yaml") + return path def generate_modulemd_version(version): @@ -70,7 +73,7 @@ def create_modulemd(collection, version, stage_dir): with open(modulemd_yaml(collection), 'r') as file: modules = yaml.safe_load(file) - modules['data']['artifacts'] = {'rpms': output.splitlines()} + modules['data']['artifacts'] = {'rpms': [str(rpm, 'UTF-8') for rpm in output.splitlines()]} modules['data']['version'] = generate_modulemd_version(version) modules['data']['context'] = generate_modulemd_context(collection, version) modules_yaml = os.path.join(stage_dir, 'repodata', 'modules.yaml') @@ -85,7 +88,7 @@ def create_repository(repo_dir): check_output(['createrepo', repo_dir]) -def sync_copr_repository(collection, version, target_dir, source=False): +def sync_copr_repository(collection, version, target_dir, dist, source=False): if source: print(f"Syncing {collection} {version} Source RPM repository from Copr") else: @@ -96,9 +99,9 @@ def sync_copr_repository(collection, version, target_dir, source=False): 'reposync', '--newest-only', '--repo', - f"el8-{collection}-{version}", - '--config', - 'reposync_config.conf', + f"{dist}-{collection}-{version}", + '--repofrompath', + f"{dist}-{collection}-{version},https://download.copr.fedorainfracloud.org/results/@theforeman/{collection}-{version}-staging/rhel-{dist.replace('el', '')}-x86_64/", '--download-path', target_dir ] @@ -120,7 +123,7 @@ def main(): try: collection = sys.argv[1] version = sys.argv[2] - operating_system = sys.argv[3] + dist = sys.argv[3] except IndexError: raise SystemExit(f"Usage: {sys.argv[0]} collection version os") @@ -128,7 +131,7 @@ def main(): rpm_sync_dir = f"{base_dir}/rpms" srpm_sync_dir = f"{base_dir}/srpms" - stage_dir = f"{base_dir}/{collection}/{version}/{operating_system}/" + stage_dir = f"{base_dir}/{collection}/{version}/{dist}/" rpm_dir = f"{stage_dir}/x86_64" srpm_dir = f"{stage_dir}/source" @@ -144,16 +147,16 @@ def main(): if not os.path.exists(srpm_dir): os.makedirs(srpm_dir) - sync_copr_repository(collection, version, rpm_sync_dir) - sync_copr_repository(collection, version, srpm_sync_dir, source=True) + sync_copr_repository(collection, version, rpm_sync_dir, dist) + sync_copr_repository(collection, version, srpm_sync_dir, dist, source=True) - move_rpms_from_copr_to_stage(collection, version, srpm_sync_dir, srpm_dir, source=True) - move_rpms_from_copr_to_stage(collection, version, rpm_sync_dir, rpm_dir) + move_rpms_from_copr_to_stage(collection, version, srpm_sync_dir, srpm_dir, dist, source=True) + move_rpms_from_copr_to_stage(collection, version, rpm_sync_dir, rpm_dir, dist) create_repository(rpm_dir) create_repository(srpm_dir) - if collection in ['foreman', 'katello'] and operating_system == 'el8': + if collection in ['foreman', 'katello'] and dist == 'el8': create_modulemd(collection, version, rpm_dir)