Skip to content

Commit

Permalink
fixed pyflake indent error and extract backup_name variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ukablan-wpc committed Sep 30, 2024
1 parent 2588a85 commit 238b5db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pleskdistup/actions/distupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def get_all_repo_list_files(sources_list_path: str, sources_list_d_path: str) ->
ret.append(os.path.join(root, f))
return ret

def __init__(self,
def __init__(
self,
sources_list_path: str = "/etc/apt/sources.list",
sources_list_d_path: str = "/etc/apt/sources.list.d/",
) -> None:
Expand Down
24 changes: 15 additions & 9 deletions pleskdistup/common/src/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,30 @@ def backup_exists(filename: str, ext: str = DEFAULT_BACKUP_EXTENSION) -> bool:
return os.path.exists(filename + ext)


def restore_file_from_backup(filename: str, remove_if_no_backup: bool = False,
ext: str = DEFAULT_BACKUP_EXTENSION) -> None:
def restore_file_from_backup(
filename: str,
remove_if_no_backup: bool = False,
ext: str = DEFAULT_BACKUP_EXTENSION,
) -> None:
if os.path.exists(filename + ext):
shutil.move(filename + ext, filename)
elif remove_if_no_backup and os.path.exists(filename):
os.remove(filename)


def remove_backup(filename: str,
raise_exception: bool = True,
logf : typing.Optional[typing.Callable] = None,
ext: str = DEFAULT_BACKUP_EXTENSION) -> None:
def remove_backup(
filename: str,
raise_exception: bool = True,
logf: typing.Optional[typing.Callable[[str], typing.Any]] = None,
ext: str = DEFAULT_BACKUP_EXTENSION,
) -> None:
backup_name = filename + ext
try:
if os.path.exists(filename + ext):
os.remove(filename + ext)
if os.path.exists(backup_name):
os.remove(backup_name)
except Exception as ex:
if logf is not None:
logf(f"failed to remove backup ({filename}): {ex}")
logf(f"failed to remove backup ({backup_name}): {ex}")
if raise_exception:
raise

Expand Down

0 comments on commit 238b5db

Please sign in to comment.