Completed
Push — master ( 419779...7515a9 )
by Charles
02:09
created

outputCommand()   A

Complexity

Conditions 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.4746

Importance

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