From c6ed85c5f01eb3d2b4210e8e7a0fd82113568bbf Mon Sep 17 00:00:00 2001 From: Anant Date: Mon, 2 Jun 2014 11:55:51 -0600 Subject: [PATCH 1/2] added compatibility for python 2.6 for ssh_read command --- ec2/spark_ec2.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ec2/spark_ec2.py b/ec2/spark_ec2.py index 8b056f5ea734c..f874b07a62b5f 100755 --- a/ec2/spark_ec2.py +++ b/ec2/spark_ec2.py @@ -670,6 +670,11 @@ def ssh(host, opts, command): def ssh_read(host, opts, command): + if sys.version_info < (2, 7): + return subprocess.Popen( + ssh_command(opts) + ['%s@%s' % + (opts.user, host), stringify_command(command)], + stdout=subprocess.PIPE).stdout return subprocess.check_output( ssh_command(opts) + ['%s@%s' % (opts.user, host), stringify_command(command)]) From 4ca441d4612ac4b228b83e94cd4b7e899bd1371d Mon Sep 17 00:00:00 2001 From: Anant Date: Tue, 10 Jun 2014 16:34:31 -0600 Subject: [PATCH 2/2] Implmented check_optput withinthe module to work with python 2.6 --- ec2/spark_ec2.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ec2/spark_ec2.py b/ec2/spark_ec2.py index f874b07a62b5f..8ef9a788dff78 100755 --- a/ec2/spark_ec2.py +++ b/ec2/spark_ec2.py @@ -669,13 +669,22 @@ def ssh(host, opts, command): tries = tries + 1 +def _check_output(*popenargs, **kwargs): + if 'stdout' in kwargs: + raise ValueError('stdout argument not allowed, it will be overridden.') + process = subprocess.Popen(stdout=PIPE, *popenargs, **kwargs) + output, unused_err = process.communicate() + retcode = process.poll() + if retcode: + cmd = kwargs.get("args") + if cmd is None: + cmd = popenargs[0] + raise subprocess.CalledProcessError(retcode, cmd, output=output) + return output + + def ssh_read(host, opts, command): - if sys.version_info < (2, 7): - return subprocess.Popen( - ssh_command(opts) + ['%s@%s' % - (opts.user, host), stringify_command(command)], - stdout=subprocess.PIPE).stdout - return subprocess.check_output( + return _check_output( ssh_command(opts) + ['%s@%s' % (opts.user, host), stringify_command(command)])