feat(kiauh): add helper methods to check for installed packages

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2023-12-16 15:38:23 +01:00
parent e121ba8a62
commit f62c10dc8b
2 changed files with 41 additions and 1 deletions

View File

@@ -10,7 +10,11 @@
# ======================================================================= #
from datetime import datetime
from typing import Dict, Literal
from typing import Dict, Literal, List
from kiauh.utils.constants import COLOR_CYAN, RESET_FORMAT
from kiauh.utils.logger import Logger
from kiauh.utils.system_utils import check_package_install, install_system_packages
def get_current_date() -> Dict[Literal["date", "time"], str]:
@@ -23,3 +27,19 @@ def get_current_date() -> Dict[Literal["date", "time"], str]:
time: str = now.strftime("%H-%M-%S")
return {"date": date, "time": time}
def check_install_dependencies(deps: List[str]) -> None:
"""
Common helper method to check if dependencies are installed
and if not, install them automatically |
:param deps: List of strings of package names to check if installed
:return: None
"""
requirements = check_package_install(deps)
if requirements:
Logger.print_status("Installing dependencies ...")
Logger.print_info("The following packages need installation:")
for _ in requirements:
print(f"{COLOR_CYAN}{_}{RESET_FORMAT}")
install_system_packages(requirements)