Completed
Push — master ( 790092...745d04 )
by Charles
02:04
created

output_command()   A

Complexity

Conditions 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 14
ccs 6
cts 6
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
3 1
"""
4
    Helper functions to run shell commands
5
"""
6
7 1
import subprocess
8 1
from subprocess import CalledProcessError
9
10 1
from git_app_version.helper.pyversion import PY3
11
12 1
try:
13 1
    from subprocess import DEVNULL  # py3k
14
except ImportError:
15
    import os
16
    DEVNULL = open(os.devnull, 'wb')
17
18
19 1
def output_command(args, cwd=None):
20
    """
21
        run a shell command and return its output
22
    """
23 1
    try:
24 1
        output = subprocess.check_output(
25
            args,
26
            cwd=cwd,
27
            universal_newlines=True,
28
            stderr=subprocess.STDOUT)
29 1
    except CalledProcessError:
30 1
        output = ''
31
32 1
    return output if PY3 else output.decode('utf-8')
33
34 1
def call_command(args, cwd=None):
35
    """
36
        run a shell command and return its exit code
37
    """
38
    return subprocess.call(args, cwd=cwd, stderr=DEVNULL)
39