Browse Source

Refactor confirmations into confirm-function

merge-requests/1/head
Markus Mittendrein 5 months ago
parent
commit
4062d6fdb4
1 changed files with 7 additions and 6 deletions
  1. 7
    6
      cfgs.py

+ 7
- 6
cfgs.py View File

@@ -56,6 +56,10 @@ def check_dependencies():
56 56
 
57 57
     return status
58 58
 
59
+def confirm(message, color=bcolors.WARNING):
60
+    status = input(color_message(color, message + " [y/N]: "))
61
+    return status and (status == "y" or status == "Y")
62
+
59 63
 def print_splash():
60 64
     print_color(bcolors.HEADER, "---=== cfgs ===---")
61 65
     print("Version: " + CONFIG_SYNC_VERSION)
@@ -75,8 +79,7 @@ def init_dialog():
75 79
     print()
76 80
 
77 81
     if config['DEFAULT']['INITIALIZED']:
78
-        reinitialize = input(color_message(bcolors.WARNING, "WARNING: cfgs has already been initialized! Do you really want to change the configuration? [y/N]: "))
79
-        if not reinitialize or reinitialize != "y":
82
+        if not confirm("WARNING: cfgs has already been initialized! Do you really want to change the configuration?"):
80 83
             print("Skipping new initialization!")
81 84
             sys.exit(0)
82 85
 
@@ -372,8 +375,7 @@ def remove_file(filepath):
372 375
         os.makedirs(target_directory)
373 376
 
374 377
     if os.path.exists(abs_path):
375
-        confirmed = input(color_message(bcolors.OKBLUE, "Do you really want to override the local file '" + abs_path + "'? [y/N]: "))
376
-        if not confirmed or confirmed != "y":
378
+        if not confirm("Do you really want to override the local file '" + abs_path + "'?", bcolors.OKBLUE):
377 379
             print_color(bcolors.WARNING, "Skipping removal process!")
378 380
             sys.exit(0)
379 381
         else:
@@ -435,8 +437,7 @@ def restore():
435 437
 
436 438
     update_local_metadata()
437 439
 
438
-    confirmed = input(color_message(bcolors.WARNING, "Do you really want to restore files from the repository? Local files will be overwritten! [y/N]: "))
439
-    if not confirmed or confirmed != "y":
440
+    if not confirm("Do you really want to restore files from the repository? Local files will be overwritten!"):
440 441
         print_color(bcolors.WARNING, "Skipping restore process!")
441 442
         sys.exit(0)
442 443
     else:

Loading…
Cancel
Save