Skip to content

Commit

Permalink
add checker for repo.list backups
Browse files Browse the repository at this point in the history
  • Loading branch information
ukablan-wpc committed Sep 27, 2024
1 parent d1cc5d8 commit 40b1e91
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions pleskdistup/actions/distupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,50 @@ def estimate_revert_time(self) -> int:
return 20


class CheckAptReposBackups(action.CheckAction):
description: str
_name: str
sources_list_path: str
sources_list_d_path: str

@staticmethod
def get_all_repo_list_files(sources_list_path: str, sources_list_d_path: str) -> typing.List[str]:
ret = [sources_list_path]
for root, _, filenames in os.walk(sources_list_d_path):
for f in filenames:
if f.endswith(".list"):
ret.append(os.path.join(root, f))
return ret

def __init__(self,
sources_list_path: str = "/etc/apt/sources.list",
sources_list_d_path: str = "/etc/apt/sources.list.d/",
) -> None:
self._name = "Check repo.list leftovers from previous conversion"
self.description = "These repo.list files are found with backups, please check/restore them, and delete the backups: {}"
self.sources_list_path = sources_list_path
self.sources_list_d_path = sources_list_d_path

@property
def name(self) -> str:
return self._name.format(self)

@name.setter
def name(self, val: str) -> None:
self._name = val

def _do_check(self) -> bool:
log.debug(f"Checking leftover repo.list files")
archived_files = []
for f in CheckAptReposBackups.get_all_repo_list_files(self.sources_list_path, self.sources_list_d_path):
if files.backup_exists(f):
archived_files.append(f)
if archived_files:
self.description = self.description.format(",".join(archived_files))
return False
return True


class ReplaceAptReposRegexp(action.ActiveAction):
from_regexp: str
to_regexp: str
Expand Down Expand Up @@ -191,12 +235,8 @@ def _apply_replace_to_file(self, fpath: str, ptrn: re.Pattern, to_regexp: str) -
f.writelines(new_lines)

def _get_all_repo_list_files(self) -> typing.List[str]:
ret = [self.sources_list_path]
for root, _, filenames in os.walk(self.sources_list_d_path):
for f in filenames:
if f.endswith(".list"):
ret.append(os.path.join(root, f))
return ret
return CheckAptReposBackups.get_all_repo_list_files(self.sources_list_path,
self.sources_list_d_path)

def _rm_backups(self) -> None:
for f in self._get_all_repo_list_files():
Expand Down

0 comments on commit 40b1e91

Please sign in to comment.