mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-24 08:13:36 +05:00
feat(kiauh): add helper methods to check for installed packages
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -10,7 +10,11 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
|
||||||
from datetime import datetime
|
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]:
|
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")
|
time: str = now.strftime("%H-%M-%S")
|
||||||
|
|
||||||
return {"date": date, "time": time}
|
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)
|
||||||
|
|||||||
@@ -169,6 +169,26 @@ def update_system_package_lists(silent: bool, rls_info_change=False) -> None:
|
|||||||
kill(f"Error updating system package list:\n{e.stderr.decode()}")
|
kill(f"Error updating system package list:\n{e.stderr.decode()}")
|
||||||
|
|
||||||
|
|
||||||
|
def check_package_install(packages: List[str]) -> List[str]:
|
||||||
|
"""
|
||||||
|
Checks the system for installed packages |
|
||||||
|
:param packages: List of strings of package names
|
||||||
|
:return: A list containing the names of packages that are not installed
|
||||||
|
"""
|
||||||
|
not_installed = []
|
||||||
|
for package in packages:
|
||||||
|
command = ["dpkg-query", "f'${Status}'", "--show", package]
|
||||||
|
result = subprocess.run(
|
||||||
|
command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True
|
||||||
|
)
|
||||||
|
if "installed" not in result.stdout.strip("'").split():
|
||||||
|
not_installed.append(package)
|
||||||
|
else:
|
||||||
|
Logger.print_ok(f"{package} already installed.")
|
||||||
|
|
||||||
|
return not_installed
|
||||||
|
|
||||||
|
|
||||||
def install_system_packages(packages: List[str]) -> None:
|
def install_system_packages(packages: List[str]) -> None:
|
||||||
"""
|
"""
|
||||||
Installs a list of system packages |
|
Installs a list of system packages |
|
||||||
|
|||||||
Reference in New Issue
Block a user