Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move additional checks based on types from the new submodule #19

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/leapp_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"),
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 36 additions & 3 deletions src/rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
Loading