s4-pycommon: support 'none' as an option in confirm
authorAndrew Tridgell <tridge@samba.org>
Tue, 5 Jul 2011 03:02:48 +0000 (13:02 +1000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 5 Jul 2011 05:10:03 +0000 (07:10 +0200)
this allows the user to ask for none of the changes of this type

Pair-Programmed-With: Amitay Isaacs <amitay@gmail.com>

source4/scripting/python/samba/common.py

index ebb3f88733079eb31fc9d2dff392cc96062e3af3..6eeace594359e4ab41a3a9a2762f9d67827c8269 100644 (file)
@@ -27,13 +27,26 @@ def confirm(msg, forced = False, allow_all=False):
         print("%s [YES]" % msg)
         return True
 
+    mapping = {
+        'Y': True,
+        'YES': True,
+        '': False,
+        'N': False,
+        'NO': False,
+        }
+
+    prompt = '[y/N]'
+
     if allow_all:
-        v = raw_input(msg + ' [y/N/all] ')
-        if v.upper() == 'ALL':
-            return "ALL"
-        return v.upper() in ['Y', 'YES']
-    else:
-        v = raw_input(msg + ' [y/N] ')
-        return v.upper() in ['Y', 'YES']
+        mapping['ALL'] = 'ALL'
+        mapping['NONE'] = 'NONE'
+        prompt = '[y/N/all/none]'
+
+    while True:
+        v = raw_input(msg + ' %s ' % prompt)
+        v = v.upper()
+        if v in mapping:
+            return mapping[v]
+        print("Unknown response '%s'" % v)