s4-pycommon: allow an optional 'all' choice for confirm dialogs
authorAndrew Tridgell <tridge@samba.org>
Tue, 5 Jul 2011 02:38:31 +0000 (12:38 +1000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 5 Jul 2011 05:10:03 +0000 (07:10 +0200)
when asking the user to confirm an action, allow for an 'all'
choice, which will be used to allow the user to confirm all future
requests of the same type

source4/scripting/python/samba/common.py

index a2a49627972d35488e7a79b8e76404f0ced5272e..ebb3f88733079eb31fc9d2dff392cc96062e3af3 100644 (file)
@@ -18,7 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-def confirm(msg, forced = False):
+def confirm(msg, forced = False, allow_all=False):
     """confirm an action with the user
         :param msg: A string to print to the user
         :param forced: Are the answer forced
@@ -27,7 +27,13 @@ def confirm(msg, forced = False):
         print("%s [YES]" % msg)
         return True
 
-    v = raw_input(msg + ' [y/N] ')
-    return v.upper() in ['Y', 'YES']
+    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']