mirror of
https://github.com/KrystianD/mikrotik_configurator.git
synced 2025-07-07 16:44:34 +02:00
initial commit
This commit is contained in:
commit
cb6a0f8d27
31 changed files with 880 additions and 0 deletions
35
mikrotik_configurator/utils.py
Normal file
35
mikrotik_configurator/utils.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import sys
|
||||
|
||||
|
||||
def write_text_file(path, content):
|
||||
with open(path, "wt", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
|
||||
|
||||
def read_text_file(path):
|
||||
with open(path, "rt") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def query_yes_no(question, default="yes"):
|
||||
valid = {"yes": True, "y": True, "ye": True,
|
||||
"no": False, "n": False}
|
||||
if default is None:
|
||||
prompt = " [y/n] "
|
||||
elif default == "yes":
|
||||
prompt = " [Y/n] "
|
||||
elif default == "no":
|
||||
prompt = " [y/N] "
|
||||
else:
|
||||
raise ValueError("invalid default answer: '%s'" % default)
|
||||
|
||||
while True:
|
||||
sys.stdout.write(question + prompt)
|
||||
choice = input().lower()
|
||||
if default is not None and choice == '':
|
||||
return valid[default]
|
||||
elif choice in valid:
|
||||
return valid[choice]
|
||||
else:
|
||||
sys.stdout.write("Please respond with 'yes' or 'no' "
|
||||
"(or 'y' or 'n').\n")
|
Loading…
Add table
Add a link
Reference in a new issue