jp (base): new confirmOrQuit helper method to ask confirmation to user, and quit if he cancel
This commit is contained in:
parent
c762d0cc31
commit
60eab27872
3 changed files with 20 additions and 18 deletions
|
|
@ -546,6 +546,14 @@ class Jp(object):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
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):
|
def quitFromSignal(self, errcode=0):
|
||||||
"""Same as self.quit, but from a signal handler
|
"""Same as self.quit, but from a signal handler
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,11 +140,7 @@ class NodeDelete(base.CommandBase):
|
||||||
else:
|
else:
|
||||||
message = _(u"Are you sure to delete node [{node_id}] on service [{service}] ?").format(
|
message = _(u"Are you sure to delete node [{node_id}] on service [{service}] ?").format(
|
||||||
node_id=self.args.node, service=self.args.service)
|
node_id=self.args.node, service=self.args.service)
|
||||||
|
self.host.confirmOrQuit(message, _(u"node deletion cancelled"))
|
||||||
res = raw_input("{} (y/N)? ".format(message))
|
|
||||||
if res not in ("y", "Y"):
|
|
||||||
self.disp(_(u"node deletion cancelled"))
|
|
||||||
self.host.quit(2)
|
|
||||||
|
|
||||||
self.host.bridge.psNodeDelete(
|
self.host.bridge.psNodeDelete(
|
||||||
self.args.service,
|
self.args.service,
|
||||||
|
|
@ -572,10 +568,7 @@ class Delete(base.CommandBase):
|
||||||
self.parser.error(_(u"You need to specify an item to delete"))
|
self.parser.error(_(u"You need to specify an item to delete"))
|
||||||
if not self.args.force:
|
if not self.args.force:
|
||||||
message = _(u"Are you sure to delete item {item_id} ?").format(item_id=self.args.item)
|
message = _(u"Are you sure to delete item {item_id} ?").format(item_id=self.args.item)
|
||||||
res = raw_input("{} (y/N)? ".format(message))
|
self.host.confirmOrQuit(message, _(u"item deletion cancelled"))
|
||||||
if res not in ("y", "Y"):
|
|
||||||
self.disp(_(u"Item deletion cancelled"))
|
|
||||||
self.host.quit(2)
|
|
||||||
self.host.bridge.psRetractItem(
|
self.host.bridge.psRetractItem(
|
||||||
self.args.service,
|
self.args.service,
|
||||||
self.args.node,
|
self.args.node,
|
||||||
|
|
|
||||||
|
|
@ -59,12 +59,13 @@ class Const(constants.Const):
|
||||||
|
|
||||||
# exit codes
|
# exit codes
|
||||||
EXIT_OK = 0
|
EXIT_OK = 0
|
||||||
EXIT_ERROR = 1 # generic error, when nothing else match
|
EXIT_ERROR = 1 # generic error, when nothing else match
|
||||||
EXIT_BAD_ARG = 2 # arguments given by user are bad
|
EXIT_BAD_ARG = 2 # arguments given by user are bad
|
||||||
EXIT_BRIDGE_ERROR = 3 # can't connect to bridge
|
EXIT_BRIDGE_ERROR = 3 # can't connect to bridge
|
||||||
EXIT_BRIDGE_ERRBACK = 4 # something went wrong when calling a bridge method
|
EXIT_BRIDGE_ERRBACK = 4 # something went wrong when calling a bridge method
|
||||||
EXIT_NOT_FOUND = 16 # an item required by a command was not found
|
EXIT_NOT_FOUND = 16 # an item required by a command was not found
|
||||||
EXIT_DATA_ERROR = 17 # data needed for a command is invalid
|
EXIT_DATA_ERROR = 17 # data needed for a command is invalid
|
||||||
EXIT_FILE_NOT_EXE = 126 # a file to be executed was found, but it was not an executable utility (cf. man 1 exit)
|
EXIT_USER_CANCELLED = 20 # user cancelled action
|
||||||
EXIT_CMD_NOT_FOUND = 127 # a utility to be executed was not found (cf. man 1 exit)
|
EXIT_FILE_NOT_EXE = 126 # a file to be executed was found, but it was not an executable utility (cf. man 1 exit)
|
||||||
EXIT_SIGNAL_INT = 128 # a command was interrupted by a signal (cf. man 1 exit)
|
EXIT_CMD_NOT_FOUND = 127 # a utility to be executed was not found (cf. man 1 exit)
|
||||||
|
EXIT_SIGNAL_INT = 128 # a command was interrupted by a signal (cf. man 1 exit)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue