Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add Python 2.6 support - closes #7

  • Loading branch information...
commit e5c4c00dddb1d7465bb55925f0d5a4830d7ac3a6 1 parent f1b8eb6
Adam Baxter authored October 02, 2012

Showing 2 changed files with 28 additions and 1 deletion. Show diff stats Hide diff stats

  1. 22  check_output.py
  2. 7  geturl
22  check_output.py
... ...
@@ -0,0 +1,22 @@
  1
+#from https://gist.github.com/1027906
  2
+import subprocess
  3
+
  4
+def check_output(*popenargs, **kwargs):
  5
+    r"""Run command with arguments and return its output as a byte string.
  6
+
  7
+    Backported from Python 2.7 as it's implemented as pure python on stdlib.
  8
+
  9
+    >>> check_output(['/usr/bin/python', '--version'])
  10
+    Python 2.6.2
  11
+    """
  12
+    process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
  13
+    output, unused_err = process.communicate()
  14
+    retcode = process.poll()
  15
+    if retcode:
  16
+        cmd = kwargs.get("args")
  17
+        if cmd is None:
  18
+            cmd = popenargs[0]
  19
+        error = subprocess.CalledProcessError(retcode, cmd)
  20
+        error.output = output
  21
+        raise error
  22
+    return output
7  geturl
... ...
@@ -1,6 +1,11 @@
1 1
 #!/usr/bin/python
2 2
 
3  
-from subprocess import check_output, CalledProcessError
  3
+from subprocess import CalledProcessError
  4
+try:
  5
+	from subprocess import check_output
  6
+except ImportError:
  7
+	from check_output import check_output
  8
+
4 9
 import json
5 10
 import sys
6 11
 import os

0 notes on commit e5c4c00

Please sign in to comment.
Something went wrong with that request. Please try again.