feat: add deprecated decorator

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-05-02 21:51:35 +02:00
parent 4a5d1a971a
commit 067a102b6b
2 changed files with 24 additions and 0 deletions

22
kiauh/utils/decorators.py Normal file
View File

@@ -0,0 +1,22 @@
# ======================================================================= #
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
# #
# 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

View File

@@ -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}"