From 4062d6fdb42759e4bc8a833d3551b3c6ed8d23eb Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Fri, 30 Nov 2018 19:11:46 +0100 Subject: [PATCH] Refactor confirmations into confirm-function --- cfgs.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cfgs.py b/cfgs.py index 4d66ff5..9ad3dbf 100755 --- a/cfgs.py +++ b/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: