common/migration.py
changeset 2738 e7e46121a4f9
parent 2615 1ea41b7c0836
child 2897 2658f432284c
equal deleted inserted replaced
2737:aaef49a3c39b 2738:e7e46121a4f9
   181         else:
   181         else:
   182             ask_confirm = True
   182             ask_confirm = True
   183         if not ask_confirm or self.confirm(msg):
   183         if not ask_confirm or self.confirm(msg):
   184             return meth(*args, **kwargs)
   184             return meth(*args, **kwargs)
   185 
   185 
   186     def confirm(self, question, shell=True, abort=True, retry=False):
   186     def confirm(self, question, shell=True, abort=True, retry=False, default='y'):
   187         """ask for confirmation and return true on positive answer
   187         """ask for confirmation and return true on positive answer
   188 
   188 
   189         if `retry` is true the r[etry] answer may return 2
   189         if `retry` is true the r[etry] answer may return 2
   190         """
   190         """
   191         possibleanswers = ['Y','n']
   191         possibleanswers = ['y','n']
   192         if abort:
   192         if abort:
   193             possibleanswers.append('abort')
   193             possibleanswers.append('abort')
   194         if shell:
   194         if shell:
   195             possibleanswers.append('shell')
   195             possibleanswers.append('shell')
   196         if retry:
   196         if retry:
   197             possibleanswers.append('retry')
   197             possibleanswers.append('retry')
   198         try:
   198         try:
   199             answer = ASK.ask(question, possibleanswers, 'Y')
   199             answer = ASK.ask(question, possibleanswers, default)
   200         except (EOFError, KeyboardInterrupt):
   200         except (EOFError, KeyboardInterrupt):
   201             answer = 'abort'
   201             answer = 'abort'
   202         if answer == 'n':
   202         if answer == 'n':
   203             return False
   203             return False
   204         if answer == 'retry':
   204         if answer == 'retry':