aboutsummaryrefslogtreecommitdiff
path: root/lava_tool/utils.py
blob: 1982cfcfba6b4bb9c332d711838b0810fa150135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Copyright (C) 2013 Linaro Limited
#
# Author: Milo Casagrande <milo.casagrande@linaro.org>
#
# This file is part of lava-tool.
#
# lava-tool is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation
#
# lava-tool is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lava-tool.  If not, see <http://www.gnu.org/licenses/>.

import os
import subprocess


def has_command(command):
    """Checks that the given command is available.

    :param command: The name of the command to check availability.
    """
    command_available = True
    try:
        subprocess.check_call(["which", command],
                              stdout=open(os.path.devnull, 'w'))
    except subprocess.CalledProcessError:
        command_available = False
    return command_available