diff --git a/pungi/scripts/create_packages_json.py b/pungi/scripts/create_packages_json.py index f54b7a02..1274945f 100644 --- a/pungi/scripts/create_packages_json.py +++ b/pungi/scripts/create_packages_json.py @@ -14,7 +14,7 @@ import os import re import tempfile from collections import defaultdict -from typing import AnyStr, Dict, List, Optional, Any, Iterator +from typing import AnyStr, Dict, List, Any, Iterator import binascii import createrepo_c as cr @@ -65,7 +65,7 @@ class RepoInfo: # Only layout of specific package (which don't exist # in a reference repository) will be taken as example is_reference: bool = False - strict_arch: bool = False + repo_type: str = 'present' class PackagesGenerator: @@ -262,7 +262,11 @@ class PackagesGenerator: ) ) all_packages = defaultdict(lambda: {'variants': list()}) - for repo_info in self.repos: + for repo_info in sorted( + self.repos, + key=lambda i: i.repo_type, + reverse=True, + ): repomd_records = self._get_repomd_records( repo_info=repo_info, ) @@ -298,6 +302,8 @@ class PackagesGenerator: all_packages[package_key]['arch'] = package_arch all_packages[package_key]['package'] = package all_packages[package_key]['type'] = repo_info.is_reference + elif repo_info.repo_type == 'absent' and (repo_info.name, repo_info.arch) in all_packages[package_key]['variants']: + all_packages[package_key]['variants'].remove((repo_info.name, repo_info.arch)) # replace an older package if it's not reference or # a newer package is from reference repo elif (not all_packages[package_key]['type'] or @@ -404,6 +410,14 @@ def create_parser(): choices=['yes', 'no'], required=True, ) + parser.add_argument( + '--repo-type', + action='append', + type=str, + help='Packages from repository will be removed or added to variant', + choices=['present', 'absent'], + required=True, + ) parser.add_argument( '--excluded-packages', nargs='+', @@ -436,13 +450,14 @@ def cli_main(): args = create_parser().parse_args() repos = [] for repo_path, repo_folder, repo_name, \ - repo_arch, is_remote, is_reference in zip( + repo_arch, is_remote, is_reference, repo_type in zip( args.repo_path, args.repo_folder, args.repo_name, args.repo_arch, args.is_remote, args.is_reference, + args.repo_type, ): repos.append(RepoInfo( path=repo_path, @@ -450,7 +465,8 @@ def cli_main(): name=repo_name, arch=repo_arch, is_remote=True if is_remote == 'yes' else False, - is_reference=True if is_reference == 'yes' else False + is_reference=True if is_reference == 'yes' else False, + repo_type=repo_type, )) pg = PackagesGenerator( repos=repos,