jp (base): new confirmOrQuit helper method to ask confirmation to user, and quit if he cancel

This commit is contained in:
Goffi 2018-03-31 18:21:56 +02:00
commit 60eab27872

View file

@ -546,6 +546,14 @@ class Jp(object):
except AttributeError:
pass
def confirmOrQuit(self, message, cancel_message=_(u"action cancelled by user")):
"""Request user to confirm action, and quit if he doesn't"""
res = raw_input("{} (y/N)? ".format(message))
if res not in ("y", "Y"):
self.disp(cancel_message)
self.quit(C.EXIT_USER_CANCELLED)
def quitFromSignal(self, errcode=0):
"""Same as self.quit, but from a signal handler