Michael Pasternak has uploaded a new change for review. Change subject: cli: implement /exit events listener ......................................................................
cli: implement /exit events listener ExitListener is listens for the /exit events and triggers /disconnect command, this way even if shell will be killed via ctrl-d event (not via standard way of exiting - /exit command), /disconnect command still will be triggered releasing local and remote resources. Change-Id: If5dcd1a7433f71f4b4321641b168e72659f13058 Signed-off-by: Michael pasternak <[email protected]> --- M src/ovirtcli/command/disconnect.py A src/ovirtcli/listeners/exitlistener.py M src/ovirtcli/shell/engineshell.py 3 files changed, 48 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/23/20323/1 diff --git a/src/ovirtcli/command/disconnect.py b/src/ovirtcli/command/disconnect.py index e50917d..536b12b 100644 --- a/src/ovirtcli/command/disconnect.py +++ b/src/ovirtcli/command/disconnect.py @@ -38,7 +38,6 @@ """ def execute(self): - stdout = self.context.terminal.stdout connection = self.context.connection if connection is None: self.error(Messages.Error.NOT_CONNECTED) @@ -51,5 +50,5 @@ self.context.status = ExecutionContext.COMMAND_ERROR finally: self.context.history.disable() - stdout.write(OvirtCliSettings.DISCONNECTED_TEMPLATE) - self.context.connection = None + self.write(OvirtCliSettings.DISCONNECTED_TEMPLATE) + self.context.connection = None diff --git a/src/ovirtcli/listeners/exitlistener.py b/src/ovirtcli/listeners/exitlistener.py new file mode 100644 index 0000000..65fee27 --- /dev/null +++ b/src/ovirtcli/listeners/exitlistener.py @@ -0,0 +1,43 @@ +# +# Copyright (c) 2010 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from ovirtcli.listeners.abstractlistener import AbstractListener +from ovirtcli.shell.disconnectcmdshell import DisconnectCmdShell + +class ExitListener(AbstractListener): + ''' + Listens for the exit events + ''' + + def __init__(self, shell): + """ + @param shell: EngineShell instance + """ + assert shell != None + self.__shell = shell + + def onEvent(self, *args, **kwargs): + ''' + fired when exit event is raised + + @param args: a list o args + @param kwargs: a list o kwargs + ''' + + if self.__shell.context.connection: + self.__shell.onecmd( + DisconnectCmdShell.NAME + "\n" + ) diff --git a/src/ovirtcli/shell/engineshell.py b/src/ovirtcli/shell/engineshell.py index f4872a0..8a2146a 100644 --- a/src/ovirtcli/shell/engineshell.py +++ b/src/ovirtcli/shell/engineshell.py @@ -51,6 +51,7 @@ from ovirtcli.listeners.errorlistener import ErrorListener from ovirtcli.settings import OvirtCliSettings from ovirtcli.prompt import PromptMode +from ovirtcli.listeners.exitlistener import ExitListener class EngineShell(cmd.Cmd, ConnectCmdShell, ActionCmdShell, \ ShowCmdShell, ListCmdShell, UpdateCmdShell, \ @@ -182,6 +183,7 @@ def __register_sys_listeners(self): self.onError += ErrorListener(self) + self.onExit += ExitListener(self) def __init_promt(self): self._set_prompt(mode=PromptMode.Disconnected) @@ -419,8 +421,8 @@ Ctrl+D """ + self._print("") self.onExit.fire() - self.emptyline(no_prompt=True) return True def do_exit(self, args): -- To view, visit http://gerrit.ovirt.org/20323 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If5dcd1a7433f71f4b4321641b168e72659f13058 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-cli Gerrit-Branch: master Gerrit-Owner: Michael Pasternak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
