Browse Source

Refactor confirmations into confirm-function

master
Markus Mittendrein 3 years ago
parent
commit
4062d6fdb4
  1. 13
      cfgs.py

13
cfgs.py

@ -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:

Loading…
Cancel
Save