style: rename input functions
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -25,10 +25,10 @@ from kiauh.modules.klipper.klipper_utils import (
|
|||||||
)
|
)
|
||||||
from kiauh.utils.constants import CURRENT_USER, KLIPPER_DIR, KLIPPER_ENV_DIR
|
from kiauh.utils.constants import CURRENT_USER, KLIPPER_DIR, KLIPPER_ENV_DIR
|
||||||
from kiauh.utils.input_utils import (
|
from kiauh.utils.input_utils import (
|
||||||
get_user_confirm,
|
get_confirm,
|
||||||
get_user_number_input,
|
get_number_input,
|
||||||
get_user_string_input,
|
get_string_input,
|
||||||
get_user_selection_input,
|
get_selection_input,
|
||||||
)
|
)
|
||||||
from kiauh.utils.logger import Logger
|
from kiauh.utils.logger import Logger
|
||||||
from kiauh.utils.system_utils import (
|
from kiauh.utils.system_utils import (
|
||||||
@@ -83,7 +83,7 @@ def handle_existing_instances(instance_manager: InstanceManager) -> bool:
|
|||||||
|
|
||||||
if instance_count > 0:
|
if instance_count > 0:
|
||||||
print_instance_overview(instance_list)
|
print_instance_overview(instance_list)
|
||||||
if not get_user_confirm("Add new instances?"):
|
if not get_confirm("Add new instances?"):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@@ -92,7 +92,7 @@ def handle_existing_instances(instance_manager: InstanceManager) -> bool:
|
|||||||
def install_klipper(instance_manager: InstanceManager) -> None:
|
def install_klipper(instance_manager: InstanceManager) -> None:
|
||||||
instance_list = instance_manager.get_instances()
|
instance_list = instance_manager.get_instances()
|
||||||
if_adding = " additional" if len(instance_list) > 0 else ""
|
if_adding = " additional" if len(instance_list) > 0 else ""
|
||||||
install_count = get_user_number_input(
|
install_count = get_number_input(
|
||||||
f"Number of{if_adding} Klipper instances to set up", 1, default=1
|
f"Number of{if_adding} Klipper instances to set up", 1, default=1
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ def set_instance_names(instance_list, install_count: int) -> List[Union[str, Non
|
|||||||
# or convert single instance install to multi instance install
|
# or convert single instance install to multi instance install
|
||||||
or (instance_count == 1 and install_count >= 1)
|
or (instance_count == 1 and install_count >= 1)
|
||||||
):
|
):
|
||||||
if get_user_confirm("Assign custom names?", False):
|
if get_confirm("Assign custom names?", False):
|
||||||
return assign_custom_names(instance_count, install_count, None)
|
return assign_custom_names(instance_count, install_count, None)
|
||||||
else:
|
else:
|
||||||
_range = range(1, install_count + 1)
|
_range = range(1, install_count + 1)
|
||||||
@@ -195,7 +195,7 @@ def assign_custom_names(
|
|||||||
|
|
||||||
for i in range(instance_count + install_count):
|
for i in range(instance_count + install_count):
|
||||||
question = f"Enter name for instance {i + 1}"
|
question = f"Enter name for instance {i + 1}"
|
||||||
name = get_user_string_input(question, exclude=exclude)
|
name = get_string_input(question, exclude=exclude)
|
||||||
instance_names.append(name)
|
instance_names.append(name)
|
||||||
exclude.append(name)
|
exclude.append(name)
|
||||||
|
|
||||||
@@ -227,7 +227,7 @@ def remove_multi_instance(instance_manager: InstanceManager) -> None:
|
|||||||
options = [str(i) for i in range(len(instance_list))]
|
options = [str(i) for i in range(len(instance_list))]
|
||||||
options.extend(["a", "A", "b", "B"])
|
options.extend(["a", "A", "b", "B"])
|
||||||
|
|
||||||
selection = get_user_selection_input("Select Klipper instance to remove", options)
|
selection = get_selection_input("Select Klipper instance to remove", options)
|
||||||
print(selection)
|
print(selection)
|
||||||
|
|
||||||
if selection == "b".lower():
|
if selection == "b".lower():
|
||||||
@@ -265,7 +265,7 @@ def check_user_groups():
|
|||||||
return
|
return
|
||||||
|
|
||||||
print_missing_usergroup_dialog(missing_groups)
|
print_missing_usergroup_dialog(missing_groups)
|
||||||
if not get_user_confirm(f"Add user '{CURRENT_USER}' to group(s) now?"):
|
if not get_confirm(f"Add user '{CURRENT_USER}' to group(s) now?"):
|
||||||
Logger.warn(
|
Logger.warn(
|
||||||
"Skipped adding user to required groups. You might encounter issues."
|
"Skipped adding user to required groups. You might encounter issues."
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from kiauh.utils.constants import COLOR_CYAN, RESET_FORMAT
|
|||||||
from kiauh.utils.logger import Logger
|
from kiauh.utils.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
def get_user_confirm(question: str, default_choice=True) -> bool:
|
def get_confirm(question: str, default_choice=True) -> bool:
|
||||||
options_confirm = ["y", "yes"]
|
options_confirm = ["y", "yes"]
|
||||||
options_decline = ["n", "no"]
|
options_decline = ["n", "no"]
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ def get_user_confirm(question: str, default_choice=True) -> bool:
|
|||||||
Logger.print_error("Invalid choice. Please select 'y' or 'n'.")
|
Logger.print_error("Invalid choice. Please select 'y' or 'n'.")
|
||||||
|
|
||||||
|
|
||||||
def get_user_number_input(
|
def get_number_input(
|
||||||
question: str, min_count: int, max_count=None, default=None
|
question: str, min_count: int, max_count=None, default=None
|
||||||
) -> int:
|
) -> int:
|
||||||
_question = question + f" (default={default})" if default else question
|
_question = question + f" (default={default})" if default else question
|
||||||
@@ -65,7 +65,7 @@ def get_user_number_input(
|
|||||||
Logger.print_error("Invalid choice. Please select a valid number.")
|
Logger.print_error("Invalid choice. Please select a valid number.")
|
||||||
|
|
||||||
|
|
||||||
def get_user_string_input(question: str, exclude=Optional[List]) -> str:
|
def get_string_input(question: str, exclude=Optional[List]) -> str:
|
||||||
while True:
|
while True:
|
||||||
_input = input(f"{COLOR_CYAN}###### {question}: {RESET_FORMAT}").strip()
|
_input = input(f"{COLOR_CYAN}###### {question}: {RESET_FORMAT}").strip()
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ def get_user_string_input(question: str, exclude=Optional[List]) -> str:
|
|||||||
Logger.print_error("This value is already in use/reserved.")
|
Logger.print_error("This value is already in use/reserved.")
|
||||||
|
|
||||||
|
|
||||||
def get_user_selection_input(question: str, option_list: List) -> str:
|
def get_selection_input(question: str, option_list: List) -> str:
|
||||||
while True:
|
while True:
|
||||||
_input = input(f"{COLOR_CYAN}###### {question}: {RESET_FORMAT}").strip()
|
_input = input(f"{COLOR_CYAN}###### {question}: {RESET_FORMAT}").strip()
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from pathlib import Path
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from kiauh.utils.constants import COLOR_RED, RESET_FORMAT
|
from kiauh.utils.constants import COLOR_RED, RESET_FORMAT
|
||||||
from kiauh.utils.input_utils import get_user_confirm
|
from kiauh.utils.input_utils import get_confirm
|
||||||
from kiauh.utils.logger import Logger
|
from kiauh.utils.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
@@ -56,9 +56,7 @@ def clone_repo(target_dir: Path, url: str, branch: str) -> None:
|
|||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print("Error cloning repository:", e.output.decode())
|
print("Error cloning repository:", e.output.decode())
|
||||||
else:
|
else:
|
||||||
overwrite_target = get_user_confirm(
|
overwrite_target = get_confirm("Target directory already exists. Overwrite?")
|
||||||
"Target directory already exists. Overwrite?"
|
|
||||||
)
|
|
||||||
if overwrite_target:
|
if overwrite_target:
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(target_dir)
|
shutil.rmtree(target_dir)
|
||||||
@@ -98,7 +96,7 @@ def create_python_venv(target: Path) -> None:
|
|||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print("Error setting up virtualenv:", e.output.decode())
|
print("Error setting up virtualenv:", e.output.decode())
|
||||||
else:
|
else:
|
||||||
overwrite_venv = get_user_confirm("Virtualenv already exists. Re-create?")
|
overwrite_venv = get_confirm("Virtualenv already exists. Re-create?")
|
||||||
if overwrite_venv:
|
if overwrite_venv:
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(target)
|
shutil.rmtree(target)
|
||||||
|
|||||||
Reference in New Issue
Block a user