From e87d048ee9a9f6fc14129c1b8992ca94e18f39ff Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 9 Dec 2013 02:42:56 +0100 Subject: [PATCH] Hack hack hackity hack hack - we now have check_output in 2.6! --- cstatsd/stats-machine | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cstatsd/stats-machine b/cstatsd/stats-machine index d709602..ae64557 100755 --- a/cstatsd/stats-machine +++ b/cstatsd/stats-machine @@ -3,6 +3,23 @@ import zmq, msgpack, time, psutil, yaml, os, subprocess from collections import namedtuple +# Horrible hack to make check_output exist in 2.6 +# http://stackoverflow.com/a/13160748/1332715 +if "check_output" not in dir( subprocess ): # duck punch it in! + def f(*popenargs, **kwargs): + if 'stdout' in kwargs: + raise ValueError('stdout argument not allowed, it will be overridden.') + 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] + raise subprocess.CalledProcessError(retcode, cmd) + return output + subprocess.check_output = f + ctx = zmq.Context() sock = ctx.socket(zmq.PUSH)