Skip to content

Commit 7235b00

Browse files
author
Sean Cribbs
committed
Fix version.py for 2.6 compatibility.
1 parent 68c0fe1 commit 7235b00

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

version.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,42 @@
2121

2222
from os.path import dirname, isdir, join
2323
import re
24-
from subprocess import CalledProcessError, check_output
24+
from subprocess import CalledProcessError, Popen, PIPE
25+
26+
try:
27+
from subprocess import check_output
28+
except ImportError:
29+
def check_output(*popenargs, **kwargs):
30+
r"""Run command with arguments and return its output as a byte string.
31+
32+
If the exit code was non-zero it raises a CalledProcessError. The
33+
CalledProcessError object will have the return code in the returncode
34+
attribute and output in the output attribute.
35+
36+
The arguments are the same as for the Popen constructor. Example:
37+
38+
>>> check_output(["ls", "-l", "/dev/null"])
39+
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
40+
41+
The stdout argument is not allowed as it is used internally.
42+
To capture standard error in the result, use stderr=STDOUT.
43+
44+
>>> check_output(["/bin/sh", "-c",
45+
... "ls -l non_existent_file ; exit 0"],
46+
... stderr=STDOUT)
47+
'ls: non_existent_file: No such file or directory\n'
48+
"""
49+
if 'stdout' in kwargs:
50+
raise ValueError('stdout argument not allowed, it will be overridden.')
51+
process = Popen(stdout=PIPE, *popenargs, **kwargs)
52+
output, unused_err = process.communicate()
53+
retcode = process.poll()
54+
if retcode:
55+
cmd = kwargs.get("args")
56+
if cmd is None:
57+
cmd = popenargs[0]
58+
raise CalledProcessError(retcode, cmd, output=output)
59+
return output
2560

2661
version_re = re.compile('^Version: (.+)$', re.M)
2762

0 commit comments

Comments
 (0)