Refactor confirmations into confirm-function
This commit is contained in:
parent
5896df1e64
commit
4062d6fdb4
13
cfgs.py
13
cfgs.py
@ -56,6 +56,10 @@ def check_dependencies():
|
|||||||
|
|
||||||
return status
|
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():
|
def print_splash():
|
||||||
print_color(bcolors.HEADER, "---=== cfgs ===---")
|
print_color(bcolors.HEADER, "---=== cfgs ===---")
|
||||||
print("Version: " + CONFIG_SYNC_VERSION)
|
print("Version: " + CONFIG_SYNC_VERSION)
|
||||||
@ -75,8 +79,7 @@ def init_dialog():
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
if config['DEFAULT']['INITIALIZED']:
|
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 confirm("WARNING: cfgs has already been initialized! Do you really want to change the configuration?"):
|
||||||
if not reinitialize or reinitialize != "y":
|
|
||||||
print("Skipping new initialization!")
|
print("Skipping new initialization!")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
@ -372,8 +375,7 @@ def remove_file(filepath):
|
|||||||
os.makedirs(target_directory)
|
os.makedirs(target_directory)
|
||||||
|
|
||||||
if os.path.exists(abs_path):
|
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 confirm("Do you really want to override the local file '" + abs_path + "'?", bcolors.OKBLUE):
|
||||||
if not confirmed or confirmed != "y":
|
|
||||||
print_color(bcolors.WARNING, "Skipping removal process!")
|
print_color(bcolors.WARNING, "Skipping removal process!")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
@ -435,8 +437,7 @@ def restore():
|
|||||||
|
|
||||||
update_local_metadata()
|
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 confirm("Do you really want to restore files from the repository? Local files will be overwritten!"):
|
||||||
if not confirmed or confirmed != "y":
|
|
||||||
print_color(bcolors.WARNING, "Skipping restore process!")
|
print_color(bcolors.WARNING, "Skipping restore process!")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user