Skip to content

Commit 4ca441d

Browse files
Implmented check_optput withinthe module to work with python 2.6
1 parent c6ed85c commit 4ca441d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

ec2/spark_ec2.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,22 @@ def ssh(host, opts, command):
669669
tries = tries + 1
670670

671671

672+
def _check_output(*popenargs, **kwargs):
673+
if 'stdout' in kwargs:
674+
raise ValueError('stdout argument not allowed, it will be overridden.')
675+
process = subprocess.Popen(stdout=PIPE, *popenargs, **kwargs)
676+
output, unused_err = process.communicate()
677+
retcode = process.poll()
678+
if retcode:
679+
cmd = kwargs.get("args")
680+
if cmd is None:
681+
cmd = popenargs[0]
682+
raise subprocess.CalledProcessError(retcode, cmd, output=output)
683+
return output
684+
685+
672686
def ssh_read(host, opts, command):
673-
if sys.version_info < (2, 7):
674-
return subprocess.Popen(
675-
ssh_command(opts) + ['%s@%s' %
676-
(opts.user, host), stringify_command(command)],
677-
stdout=subprocess.PIPE).stdout
678-
return subprocess.check_output(
687+
return _check_output(
679688
ssh_command(opts) + ['%s@%s' % (opts.user, host), stringify_command(command)])
680689

681690

0 commit comments

Comments
 (0)