Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
---------------------------------------------------------------
commit 8c311014fddd2e5c7affb03a90f3b8a5f13ddd11
Author: Michal Minar <miminar(a)redhat.com>
Date: Sun Jan 19 15:14:54 2014 +0100
exit interactive mode only when LmiTerminate is raised
Do not take into account the return value of executed command when
deciding whether to stop the shell. Terminate only when LmiTerminate is
raised.
Original commit digest in openlmi-scripts repo:
97fc31be422e833232679cfb27fbcfd4ae3fde5b
---------------------------------------------------------------
cli/lmi/scripts/_metacommand/interactive.py | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/cli/lmi/scripts/_metacommand/interactive.py
b/cli/lmi/scripts/_metacommand/interactive.py
index bc31bf1..1170a94 100644
--- a/cli/lmi/scripts/_metacommand/interactive.py
+++ b/cli/lmi/scripts/_metacommand/interactive.py
@@ -42,6 +42,7 @@ class Interactive(cmd.Cmd):
cmd.Cmd.__init__(self,
stdin=parent_app.stdin, stdout=parent_app.stdout)
self.prompt = prompt
+ self._last_exit_code = 0
@property
def command_manager(self):
@@ -74,7 +75,11 @@ class Interactive(cmd.Cmd):
line_parts = shlex.split(line)
try:
# let's try to run registered subcommand
- return self.run_subcommand(line_parts)
+ retval = self.run_subcommand(line_parts)
+ if isinstance(retval, bool) or not isinstance(retval, (int, long)):
+ retval = 0 if bool(retval) or retval is None else 1
+ self._last_exit_code = retval
+ return retval
except errors.LmiCommandNotFound:
return cmd.Cmd.default(self, line)
except docopt.DocoptExit as err:
@@ -137,7 +142,7 @@ class Interactive(cmd.Cmd):
"""
Exit on End-Of-File.
"""
- return True
+ raise errors.LmiTerminate(self._last_exit_code)
def get_names(self):
"""
@@ -147,3 +152,15 @@ class Interactive(cmd.Cmd):
return [ n for n in cmd.Cmd.get_names(self)
if not n.startswith('do__')]
+ def postcmd(self, stop, _line):
+ """
+ This is called after the ``do_*`` command to postprocess its result and
+ decide whether to stop the shell. We want to stop only when
+ :py:class:`lmi.scripts.common.errors.LmiError` is raised. This
+ exception is catched upwards in call chain.
+
+ :returns: Whether to stop the shell.
+ :rtype: bool
+ """
+ return False
+