File: proc.py

package info (click to toggle)
devpi-common 3.2.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 248 kB
  • sloc: python: 1,552; makefile: 4
file content (19 lines) | stat: -rw-r--r-- 651 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import sys
from subprocess import Popen, CalledProcessError, PIPE

def check_output(*args, **kwargs):
    # subprocess.check_output does not exist on python26
    if "universal_newlines" not in kwargs:
        kwargs["universal_newlines"] = True
    popen = Popen(stdout=PIPE, *args, **kwargs)
    output, unused_err = popen.communicate()
    retcode = popen.poll()
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = args[0]
        if sys.version_info < (2,7):
            raise CalledProcessError(retcode, cmd)
        else:
            raise CalledProcessError(retcode, cmd, output=output)
    return output