Revision: 180
Author: janne.t.harkonen
Date: Wed Aug 29 22:24:52 2012
Log: move handling of read command outputs to lib
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=180
Modified:
/trunk/src/SSHLibrary/abstractclient.py
/trunk/src/SSHLibrary/library.py
=======================================
--- /trunk/src/SSHLibrary/abstractclient.py Wed Aug 29 05:46:34 2012
+++ /trunk/src/SSHLibrary/abstractclient.py Wed Aug 29 22:24:52 2012
@@ -121,27 +121,24 @@
except IOError:
raise SSHClientException("Could not read key file '%s'" %
keyfile)
- def execute_command(self, command, return_stdout, return_stderr,
- return_rc):
+ def execute_command(self, command):
+ """Execute given command over existing connection.
+
+ :returns: 3-tuple (stdout, stderr, return_code)
+ """
self.start_command(command)
- return self.read_command_output(return_stdout, return_stderr,
- return_rc)
+ return self.read_command_output()
def start_command(self, command):
+ """Execute given command over existing connection."""
self._commands.append(self._start_command(command))
- def read_command_output(self, return_stdout, return_stderr, return_rc):
- stdout, stderr, rc = self._commands.pop().read_outputs()
- ret = []
- if return_stdout:
- ret.append(stdout.rstrip('\n'))
- if return_stderr:
- ret.append(stderr.rstrip('\n'))
- if return_rc:
- ret.append(rc)
- if len(ret) == 1:
- return ret[0]
- return ret
+ def read_command_output(self):
+ """Read output of a previously started command.
+
+ :returns: 3-tuple (stdout, stderr, return_code)
+ """
+ return self._commands.pop().read_outputs()
def write(self, text, add_newline=False):
"""Write `text` in shell session.
=======================================
--- /trunk/src/SSHLibrary/library.py Wed Aug 29 22:24:27 2012
+++ /trunk/src/SSHLibrary/library.py Wed Aug 29 22:24:52 2012
@@ -299,7 +299,8 @@
"""
self._info("Executing command '%s'" % command)
opts = self._output_options(return_stdout, return_stderr,
return_rc)
- return self.ssh_client.execute_command(command, *opts)
+ stdout, stderr, rc = self.ssh_client.execute_command(command)
+ return self._return_command_output(stdout, stderr, rc, *opts)
def start_command(self, command):
"""Starts command execution on remote host.
@@ -329,7 +330,8 @@
"""
self._info("Reading output of command '%s'" % self._command)
opts = self._output_options(return_stdout, return_stderr,
return_rc)
- return self.ssh_client.read_command_output(*opts)
+ stdout, stderr, rc = self.ssh_client.read_command_output()
+ return self._return_command_output(stdout, stderr, rc, *opts)
def _output_options(self, stdout, stderr, rc):
# Handle legacy options for configuring returned outputs
@@ -342,6 +344,19 @@
return True, True, rc
return stdout, stderr, rc
+ def _return_command_output(self, stdout, stderr, rc,
+ return_stdout, return_stderr, return_rc):
+ ret = []
+ if return_stdout:
+ ret.append(stdout.rstrip('\n'))
+ if return_stderr:
+ ret.append(stderr.rstrip('\n'))
+ if return_rc:
+ ret.append(rc)
+ if len(ret) == 1:
+ return ret[0]
+ return ret
+
def write(self, text, loglevel=None):
"""Writes given text over the connection and appends newline.