Skip to content

Commit

Permalink
Use a backport for check_output that is not part of python 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
bgruening committed Sep 24, 2015
1 parent 4a4a7ca commit e8eb46b
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/galaxy/web/base/interactive_environments.py
Expand Up @@ -5,7 +5,8 @@
import stat
import random
import tempfile
from subprocess import Popen, PIPE, check_output
import subprocess
from subprocess import Popen, PIPE

from galaxy.util.bunch import Bunch
from galaxy import web
Expand All @@ -16,6 +17,32 @@
log = logging.getLogger(__name__)


# Python 2.6 does not support the check_output command.
# As a workaround we use a backport from https://gist.github.com/edufelipe/1027906
# until we do not support Python 2.6 anymore.

if "check_output" not in dir( subprocess ):
def check_output(*popenargs, **kwargs):
r"""Run command with arguments and return its output as a byte string.
Backported from Python 2.7 as it's implemented as pure python on stdlib.
>>> check_output(['/usr/bin/python', '--version'])
Python 2.6.2
"""
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
error = subprocess.CalledProcessError(retcode, cmd)
error.output = output
raise error
return output
else:
from subprocess import check_output


class InteractiveEnviornmentRequest(object):

def __init__(self, trans, plugin):
Expand Down

0 comments on commit e8eb46b

Please sign in to comment.