diff --git a/src/leapp_configs.py b/src/leapp_configs.py index d0de5c0..a9c2ac0 100644 --- a/src/leapp_configs.py +++ b/src/leapp_configs.py @@ -33,7 +33,12 @@ """ -def _do_replacement(to_change: str, replacement_list: typing.List[typing.Callable[[str], str]]) -> str: +def _do_replacement( + to_change: str, + replacement_list: typing.List[ + typing.Callable[[str], str] + ] +) -> typing.Optional[str]: if to_change is None: return None @@ -42,13 +47,13 @@ def _do_replacement(to_change: str, replacement_list: typing.List[typing.Callabl return to_change -def _do_id_replacement(id: str) -> str: +def _do_id_replacement(id: typing.Optional[str]) -> typing.Optional[str]: return _do_replacement(id, [ lambda to_change: "alma-" + to_change, ]) -def _do_name_replacement(name: str) -> str: +def _do_name_replacement(name: typing.Optional[str]) -> typing.Optional[str]: return _do_replacement(name, [ lambda to_change: "Alma " + to_change, lambda to_change: to_change.replace("Enterprise Linux 7", "Enterprise Linux 8"), @@ -107,7 +112,7 @@ def _fix_postgresql_official_repository(to_change: str) -> str: return to_change -def _do_url_replacement(url: str) -> str: +def _do_url_replacement(url: typing.Optional[str]) -> typing.Optional[str]: return _do_replacement(url, [ _fixup_old_php_urls, _fix_rackspace_repository, @@ -128,7 +133,7 @@ def _do_url_replacement(url: str) -> str: ]) -def _do_common_replacement(line: str) -> str: +def _do_common_replacement(line: typing.Optional[str]) -> typing.Optional[str]: return _do_replacement(line, [ lambda to_change: to_change.replace("EPEL-7", "EPEL-8"), # We can't check repository gpg because the key is not stored in the temporary file system @@ -137,7 +142,13 @@ def _do_common_replacement(line: str) -> str: ]) -def is_repo_ok(id: str, name: str, url: str, metalink: str, mirrorlist: str) -> bool: +def is_repo_ok( + id: typing.Optional[str], + name: typing.Optional[str], + url: typing.Optional[str], + metalink: typing.Optional[str], + mirrorlist: typing.Optional[str] +) -> bool: if name is None: log.warn("Repository info for '[{id}]' has no a name".format(id=id)) return False @@ -185,7 +196,8 @@ def adopt_repositories(repofile: str, ignore: typing.List = None) -> None: dst.write(repo_format.format(id=id, name=name, url=url)) for line in (_do_common_replacement(add_line) for add_line in additional_lines): - dst.write(line) + if line is not None: + dst.write(line) shutil.move(repofile + ".next", repofile) @@ -216,6 +228,10 @@ def add_repositories_mapping(repofiles: typing.List[str], ignore: typing.List = new_id = _do_id_replacement(id) name = _do_name_replacement(name) + if new_id is None or name is None: + log.warn(f"Skip repository '{id}' since it has no next id or name") + continue + if url is not None: url = _do_url_replacement(url) repo_format = REPO_HEAD_WITH_URL @@ -225,11 +241,15 @@ def add_repositories_mapping(repofiles: typing.List[str], ignore: typing.List = else: url = _do_url_replacement(mirrorlist) repo_format = REPO_HEAD_WITH_MIRRORLIST + if url is None: + log.warn(f"Skip repository '{id}' since it has no baseurl, metalink and mirrorlist") + continue leapp_repos_file.write(repo_format.format(id=new_id, name=name, url=url)) for line in (_do_common_replacement(add_line) for add_line in additional_lines): - leapp_repos_file.write(line) + if line is not None: + leapp_repos_file.write(line) # Special case for plesk repository. We need to add dist repository to install some of plesk packages # We support metalink for plesk repository, regardless of the fact we don't use them now diff --git a/src/rpm.py b/src/rpm.py index 197a2e2..180af10 100644 --- a/src/rpm.py +++ b/src/rpm.py @@ -23,7 +23,18 @@ """ -def extract_repodata(repofile: str) -> typing.Iterable[typing.Tuple[str, str, str, str, str, typing.List[str]]]: +def extract_repodata( + repofile: str +) -> typing.Iterable[ + typing.Tuple[ + typing.Optional[str], + typing.Optional[str], + typing.Optional[str], + typing.Optional[str], + typing.Optional[str], + typing.List[str] + ] +]: id = None name = None url = None @@ -70,7 +81,15 @@ def extract_repodata(repofile: str) -> typing.Iterable[typing.Tuple[str, str, st yield (id, name, url, metalink, mirrorlist, additional) -def write_repodata(repofile: str, id: str, name: str, url: str, metalink: str, mirrorlist: str, additional: typing.List[str]) -> None: +def write_repodata( + repofile: str, + id: typing.Optional[str], + name: typing.Optional[str], + url: typing.Optional[str], + metalink: typing.Optional[str], + mirrorlist: typing.Optional[str], + additional: typing.List[str] +) -> None: repo_format = REPO_HEAD_WITH_URL if url is None and metalink is not None: url = metalink @@ -85,7 +104,21 @@ def write_repodata(repofile: str, id: str, name: str, url: str, metalink: str, m dst.write(line) -def remove_repositories(repofile: str, conditions: typing.Callable[[str, str, str, str, str], bool]) -> None: +def remove_repositories( + repofile: str, + conditions: typing.Iterable[ + typing.Callable[ + [ + typing.Optional[str], + typing.Optional[str], + typing.Optional[str], + typing.Optional[str], + typing.Optional[str] + ], + bool + ] + ] +) -> None: for id, name, url, metalink, mirrorlist, additional_lines in extract_repodata(repofile): remove = False for condition in conditions: