ALBS-334: Make the ability of Pungi to give module_defaults from remote sources

This commit is contained in:
soksanichenko 2022-04-30 00:27:31 +03:00
parent 34eb45c7ec
commit 38ea822260
1 changed files with 17 additions and 8 deletions

View File

@ -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: