summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-07-05 13:02:48 +1000
committerAndrew Tridgell <tridge@samba.org>2011-07-05 07:10:03 +0200
commitbce1be36dca87bea3b1bdbad86a8265fa1d4bed9 (patch)
treeedeca4ac109574308d63fd00b247ec1ac86f38b6
parentc6985f1e7ed6f2d4d7e39e3eea7ed714f6c6ae06 (diff)
downloadsamba-bce1be36dca87bea3b1bdbad86a8265fa1d4bed9.tar.gz
samba-bce1be36dca87bea3b1bdbad86a8265fa1d4bed9.tar.bz2
samba-bce1be36dca87bea3b1bdbad86a8265fa1d4bed9.zip
s4-pycommon: support 'none' as an option in confirm
this allows the user to ask for none of the changes of this type Pair-Programmed-With: Amitay Isaacs <amitay@gmail.com>
-rw-r--r--source4/scripting/python/samba/common.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/source4/scripting/python/samba/common.py b/source4/scripting/python/samba/common.py
index ebb3f88733..6eeace5943 100644
--- a/source4/scripting/python/samba/common.py
+++ b/source4/scripting/python/samba/common.py
@@ -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)