Commit 4062d6fd authored by Markus Mittendrein's avatar Markus Mittendrein

Refactor confirmations into confirm-function

parent 5896df1e
......@@ -56,6 +56,10 @@ def check_dependencies():
return status
def confirm(message, color=bcolors.WARNING):
status = input(color_message(color, message + " [y/N]: "))
return status and (status == "y" or status == "Y")
def print_splash():
print_color(bcolors.HEADER, "---=== cfgs ===---")
print("Version: " + CONFIG_SYNC_VERSION)
......@@ -75,8 +79,7 @@ def init_dialog():
print()
if config['DEFAULT']['INITIALIZED']:
reinitialize = input(color_message(bcolors.WARNING, "WARNING: cfgs has already been initialized! Do you really want to change the configuration? [y/N]: "))
if not reinitialize or reinitialize != "y":
if not confirm("WARNING: cfgs has already been initialized! Do you really want to change the configuration?"):
print("Skipping new initialization!")
sys.exit(0)
......@@ -372,8 +375,7 @@ def remove_file(filepath):
os.makedirs(target_directory)
if os.path.exists(abs_path):
confirmed = input(color_message(bcolors.OKBLUE, "Do you really want to override the local file '" + abs_path + "'? [y/N]: "))
if not confirmed or confirmed != "y":
if not confirm("Do you really want to override the local file '" + abs_path + "'?", bcolors.OKBLUE):
print_color(bcolors.WARNING, "Skipping removal process!")
sys.exit(0)
else:
......@@ -435,8 +437,7 @@ def restore():
update_local_metadata()
confirmed = input(color_message(bcolors.WARNING, "Do you really want to restore files from the repository? Local files will be overwritten! [y/N]: "))
if not confirmed or confirmed != "y":
if not confirm("Do you really want to restore files from the repository? Local files will be overwritten!"):
print_color(bcolors.WARNING, "Skipping restore process!")
sys.exit(0)
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment