diff --git a/kiauh/utils/decorators.py b/kiauh/utils/decorators.py new file mode 100644 index 0000000..a11cb72 --- /dev/null +++ b/kiauh/utils/decorators.py @@ -0,0 +1,22 @@ +# ======================================================================= # +# Copyright (C) 2020 - 2024 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/dw-0/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +# ======================================================================= # +import warnings +from typing import Callable + + +def deprecated(info: str = "", replaced_by: Callable = None) -> Callable: + def decorator(func): + def wrapper(*args, **kwargs): + msg = f"{info}{replaced_by.__name__ if replaced_by else ''}" + warnings.warn(msg, category=DeprecationWarning, stacklevel=2) + return func(*args, **kwargs) + + return wrapper + + return decorator diff --git a/kiauh/utils/fs_utils.py b/kiauh/utils/fs_utils.py index e4ad4e8..4ac3df9 100644 --- a/kiauh/utils/fs_utils.py +++ b/kiauh/utils/fs_utils.py @@ -24,6 +24,7 @@ from utils import ( NGINX_CONFD, NGINX_SITES_ENABLED, ) +from utils.decorators import deprecated from utils.logger import Logger @@ -59,6 +60,7 @@ def create_symlink(source: Path, target: Path, sudo=False) -> None: raise +@deprecated(info="Use remove_with_sudo instead", replaced_by=remove_with_sudo) def remove_file(file_path: Path, sudo=False) -> None: try: cmd = f"{'sudo ' if sudo else ''}rm -f {file_path}"