From 38ea8222609b1d80338a7b02daff625b50003481 Mon Sep 17 00:00:00 2001 From: soksanichenko Date: Sat, 30 Apr 2022 00:27:31 +0300 Subject: [PATCH] ALBS-334: Make the ability of Pungi to give module_defaults from remote sources --- pungi/scripts/gather_modules.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pungi/scripts/gather_modules.py b/pungi/scripts/gather_modules.py index 11e38e42..1f80a0a1 100644 --- a/pungi/scripts/gather_modules.py +++ b/pungi/scripts/gather_modules.py @@ -79,6 +79,8 @@ def read_modules_yaml_from_specific_repo(repo_path: AnyStr) -> List[BytesIO]: record.location_href, ) return [read_modules_yaml(modules_yaml_path=modules_yaml_path)] + else: + return [] def collect_modules( @@ -93,10 +95,13 @@ def collect_modules( Returns: object: """ + xor_flag = grep_only_modules_defaults_data is grep_only_modules_data modules_path = os.path.join(target_dir, 'modules') module_defaults_path = os.path.join(target_dir, 'module_defaults') - os.makedirs(modules_path, exist_ok=True) - os.makedirs(module_defaults_path, exist_ok=True) + if grep_only_modules_data or xor_flag: + os.makedirs(modules_path, exist_ok=True) + if grep_only_modules_defaults_data or xor_flag: + os.makedirs(module_defaults_path, exist_ok=True) # Defaults modules can be empty, but pungi detects # empty folder while copying and raises the exception in this case Path(os.path.join(module_defaults_path, EMPTY_FILE)).touch() @@ -108,7 +113,6 @@ def collect_modules( elif is_xz_file(data[:2]): data = lzma.decompress(data) documents = yaml.load_all(data, Loader=yaml.BaseLoader) - xor_flag = grep_only_modules_defaults_data is grep_only_modules_data for doc in documents: path = None if doc['document'] == 'modulemd-defaults' and \ @@ -171,17 +175,22 @@ def cli_main(): help='Path to a directory which contains repodirs. E.g. /var/repos' ) path_group.add_argument( - '-rd', '--repodata-path', + '-rd', '--repodata-paths', required=False, type=str, - default=None, - help='Path/url to a directory with repodata dir', + nargs='+', + default=[], + help='Paths/urls to the directories with directory `repodata`', ) parser.add_argument('-t', '--target', required=True) namespace = parser.parse_args() - if namespace.repodata_path is not None: - modules = read_modules_yaml_from_specific_repo(namespace.repodata_path) + if namespace.repodata_paths: + modules = [] + for repodata_path in namespace.repodata_paths: + modules.extend(read_modules_yaml_from_specific_repo( + repodata_path, + )) elif namespace.path is not None: modules = namespace.path else: