mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 08:43:36 +05:00
feat(style): use black code style / formatter
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -11,8 +11,8 @@
|
||||
|
||||
from typing import Optional, List
|
||||
|
||||
from kiauh.utils.logger import Logger
|
||||
from kiauh.utils.constants import COLOR_CYAN, RESET_FORMAT
|
||||
from kiauh.utils.logger import Logger
|
||||
|
||||
|
||||
def get_user_confirm(question: str, default_choice=True) -> bool:
|
||||
@@ -30,7 +30,8 @@ def get_user_confirm(question: str, default_choice=True) -> bool:
|
||||
choice = (
|
||||
input(f"{COLOR_CYAN}###### {question} {def_choice} {RESET_FORMAT}")
|
||||
.strip()
|
||||
.lower())
|
||||
.lower()
|
||||
)
|
||||
|
||||
if choice in options_confirm:
|
||||
return True
|
||||
@@ -40,8 +41,9 @@ def get_user_confirm(question: str, default_choice=True) -> bool:
|
||||
Logger.print_error("Invalid choice. Please select 'y' or 'n'.")
|
||||
|
||||
|
||||
def get_user_number_input(question: str, min_count: int, max_count=None,
|
||||
default=None) -> int:
|
||||
def get_user_number_input(
|
||||
question: str, min_count: int, max_count=None, default=None
|
||||
) -> int:
|
||||
_question = question + f" (default={default})" if default else question
|
||||
_question = f"{COLOR_CYAN}###### {_question}: {RESET_FORMAT}"
|
||||
while True:
|
||||
@@ -65,8 +67,7 @@ def get_user_number_input(question: str, min_count: int, max_count=None,
|
||||
|
||||
def get_user_string_input(question: str, exclude=Optional[List]) -> str:
|
||||
while True:
|
||||
_input = (input(f"{COLOR_CYAN}###### {question}: {RESET_FORMAT}")
|
||||
.strip())
|
||||
_input = input(f"{COLOR_CYAN}###### {question}: {RESET_FORMAT}").strip()
|
||||
|
||||
if _input.isalnum() and _input not in exclude:
|
||||
return _input
|
||||
@@ -78,8 +79,7 @@ def get_user_string_input(question: str, exclude=Optional[List]) -> str:
|
||||
|
||||
def get_user_selection_input(question: str, option_list: List) -> str:
|
||||
while True:
|
||||
_input = (input(f"{COLOR_CYAN}###### {question}: {RESET_FORMAT}")
|
||||
.strip())
|
||||
_input = input(f"{COLOR_CYAN}###### {question}: {RESET_FORMAT}").strip()
|
||||
|
||||
if _input in option_list:
|
||||
return _input
|
||||
|
||||
@@ -9,12 +9,16 @@
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from kiauh.utils.constants import COLOR_GREEN, COLOR_YELLOW, COLOR_RED, \
|
||||
COLOR_MAGENTA, RESET_FORMAT
|
||||
from kiauh.utils.constants import (
|
||||
COLOR_GREEN,
|
||||
COLOR_YELLOW,
|
||||
COLOR_RED,
|
||||
COLOR_MAGENTA,
|
||||
RESET_FORMAT,
|
||||
)
|
||||
|
||||
|
||||
class Logger:
|
||||
|
||||
@staticmethod
|
||||
def info(msg):
|
||||
# log to kiauh.log
|
||||
|
||||
@@ -57,7 +57,8 @@ def clone_repo(target_dir: Path, url: str, branch: str) -> None:
|
||||
print("Error cloning repository:", e.output.decode())
|
||||
else:
|
||||
overwrite_target = get_user_confirm(
|
||||
"Target directory already exists. Overwrite?")
|
||||
"Target directory already exists. Overwrite?"
|
||||
)
|
||||
if overwrite_target:
|
||||
try:
|
||||
shutil.rmtree(target_dir)
|
||||
@@ -71,13 +72,13 @@ def clone_repo(target_dir: Path, url: str, branch: str) -> None:
|
||||
def parse_packages_from_file(source_file) -> List[str]:
|
||||
packages = []
|
||||
print("Reading dependencies...")
|
||||
with open(source_file, 'r') as file:
|
||||
with open(source_file, "r") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
if line.startswith("PKGLIST="):
|
||||
line = line.replace("\"", "")
|
||||
line = line.replace('"', "")
|
||||
line = line.replace("PKGLIST=", "")
|
||||
line = line.replace('${PKGLIST}', '')
|
||||
line = line.replace("${PKGLIST}", "")
|
||||
packages.extend(line.split())
|
||||
return packages
|
||||
|
||||
@@ -97,16 +98,15 @@ def create_python_venv(target: Path) -> None:
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Error setting up virtualenv:", e.output.decode())
|
||||
else:
|
||||
overwrite_venv = get_user_confirm(
|
||||
"Virtualenv already exists. Re-create?")
|
||||
overwrite_venv = get_user_confirm("Virtualenv already exists. Re-create?")
|
||||
if overwrite_venv:
|
||||
try:
|
||||
shutil.rmtree(target)
|
||||
create_python_venv(target)
|
||||
except OSError as e:
|
||||
Logger.print_error(
|
||||
f"Error removing existing virtualenv: {e.strerror}",
|
||||
False)
|
||||
f"Error removing existing virtualenv: {e.strerror}", False
|
||||
)
|
||||
else:
|
||||
print("Skipping re-creation of virtualenv ...")
|
||||
|
||||
@@ -144,10 +144,7 @@ def install_python_requirements(target: Path, requirements: Path) -> None:
|
||||
|
||||
def update_system_package_lists(silent: bool, rls_info_change=False) -> None:
|
||||
cache_mtime = 0
|
||||
cache_files = [
|
||||
"/var/lib/apt/periodic/update-success-stamp",
|
||||
"/var/lib/apt/lists"
|
||||
]
|
||||
cache_files = ["/var/lib/apt/periodic/update-success-stamp", "/var/lib/apt/lists"]
|
||||
for cache_file in cache_files:
|
||||
if Path(cache_file).exists():
|
||||
cache_mtime = max(cache_mtime, os.path.getmtime(cache_file))
|
||||
@@ -196,8 +193,7 @@ def create_directory(_dir: Path) -> None:
|
||||
os.makedirs(_dir, exist_ok=True)
|
||||
Logger.print_ok("Directory created!")
|
||||
else:
|
||||
Logger.print_info(
|
||||
f"Directory already exists: {_dir}\nSkip creation ...")
|
||||
Logger.print_info(f"Directory already exists: {_dir}\nSkip creation ...")
|
||||
except OSError as e:
|
||||
Logger.print_error(f"Error creating folder: {e}")
|
||||
raise
|
||||
@@ -208,5 +204,7 @@ def mask_system_service(service_name: str) -> None:
|
||||
command = ["sudo", "systemctl", "mask", service_name]
|
||||
subprocess.run(command, stderr=subprocess.PIPE, check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
Logger.print_error(f"Unable to mask system service {service_name}: {e.stderr.decode()}")
|
||||
Logger.print_error(
|
||||
f"Unable to mask system service {service_name}: {e.stderr.decode()}"
|
||||
)
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user