2022-05-17 09:58:19 +00:00
|
|
|
# No relative imports allowed in this file to be able to run server_setup.py without packages
|
|
|
|
|
2022-05-08 15:29:45 +00:00
|
|
|
import subprocess
|
|
|
|
from getpass import getpass
|
|
|
|
|
|
|
|
|
|
|
|
def run(command, **kwargs):
|
|
|
|
return subprocess.run(command, shell=True, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def box(message, context=None):
|
|
|
|
text_line = "| "
|
|
|
|
|
|
|
|
if context is not None:
|
|
|
|
text_line += context + ": "
|
|
|
|
|
|
|
|
text_line += message + " |"
|
|
|
|
|
|
|
|
separator = "=" * len(text_line)
|
|
|
|
|
|
|
|
print()
|
|
|
|
print(separator)
|
|
|
|
print(text_line)
|
|
|
|
print(separator)
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
def step(message):
|
|
|
|
continue_message = "-> Press ENTER to continue or Ctrl+C to interrupt the script <-"
|
|
|
|
upper_separator = "_" * len(continue_message)
|
|
|
|
|
|
|
|
print()
|
|
|
|
print(upper_separator)
|
|
|
|
|
|
|
|
box(message, "Next step")
|
|
|
|
|
|
|
|
print(continue_message)
|
|
|
|
getpass("")
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
def spaced_hl():
|
|
|
|
print("\n\n" + "_" * 20 + "\n\n")
|
|
|
|
|
|
|
|
|
|
|
|
def validating_input(
|
|
|
|
prompt,
|
|
|
|
options=None,
|
|
|
|
format_function=lambda ans: ans,
|
|
|
|
check_constraints_function=lambda ans: True,
|
|
|
|
):
|
|
|
|
if options is not None:
|
|
|
|
prompt += " ["
|
|
|
|
|
|
|
|
for opt in options[:-1]:
|
|
|
|
prompt += opt + "/"
|
|
|
|
|
|
|
|
prompt += options[-1] + "]: "
|
|
|
|
|
|
|
|
lowered_options = [opt.lower() for opt in options]
|
|
|
|
|
|
|
|
def adj_check_constraints_function(ans):
|
|
|
|
return ans.lower() in lowered_options and check_constraints_function(ans)
|
|
|
|
|
|
|
|
else:
|
|
|
|
prompt += ": "
|
|
|
|
adj_check_constraints_function = check_constraints_function
|
|
|
|
|
|
|
|
ans = None
|
|
|
|
first_run = True
|
|
|
|
|
|
|
|
while ans is None or not adj_check_constraints_function(ans):
|
|
|
|
if not first_run:
|
2022-05-09 00:11:28 +00:00
|
|
|
print("Invalid input!\n")
|
2022-05-08 15:29:45 +00:00
|
|
|
else:
|
|
|
|
first_run = False
|
|
|
|
|
|
|
|
ans = input(prompt)
|
|
|
|
try:
|
2022-05-09 00:11:28 +00:00
|
|
|
formatted_ans = format_function(ans)
|
2022-05-08 15:29:45 +00:00
|
|
|
except Exception as ex:
|
|
|
|
ans = None
|
|
|
|
|
2022-05-09 00:11:28 +00:00
|
|
|
return formatted_ans
|
2022-05-08 15:29:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def confirm(prompt):
|
|
|
|
ans = validating_input(
|
|
|
|
prompt,
|
|
|
|
options=("y", "n"),
|
|
|
|
format_function=lambda ans: ans.lower(),
|
|
|
|
)
|
|
|
|
|
|
|
|
if ans == "y":
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|