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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
# Copyright (C) 2016 Linaro Limited
#
# Author: Remi Duraffort <remi.duraffort@linaro.org>
#
# SPDX-License-Identifier: GPL-2.0-or-later
import os
from stat import S_IXUSR
from lava_dispatcher.utils.shell import _which_check
class DummyLogger:
def info(self, *args, **kwargs):
pass
def debug(self, *args, **kwargs):
pass
def exception(self, *args, **kwargs):
pass
def error(self, *args, **kwargs):
pass
def warning(self, *args, **kwargs):
pass
def results(self, *args, **kwargs):
pass
def marker(self, *args, **kwargs):
pass
def target(self, *args, **kwargs):
pass
class RecordingLogger:
def __init__(self):
self.logs = []
def info(self, *args, **kwargs):
self.logs.append(("info", *args, {**kwargs}))
def debug(self, *args, **kwargs):
self.logs.append(("debug", *args, {**kwargs}))
def exception(self, *args, **kwargs):
self.logs.append(("exception", *args, {**kwargs}))
def error(self, *args, **kwargs):
self.logs.append(("error", *args, {**kwargs}))
def warning(self, *args, **kwargs):
self.logs.append(("warning", *args, {**kwargs}))
def results(self, *args, **kwargs):
self.logs.append(("results", *args, {**kwargs}))
def marker(self, *args, **kwargs):
self.logs.append(("marker", *args, {**kwargs}))
def target(self, *args, **kwargs):
self.logs.append(("target", *args, {**kwargs}))
def infrastructure_error(path):
"""
Extends which into a check which sets default messages for Action validation,
without needing to raise an Exception (which is slow).
Use for quick checks on whether essential tools are installed and usable.
"""
exefile = _which_check(path, match=os.path.isfile)
if not exefile:
return "Cannot find command '%s' in $PATH" % path
# is the infrastructure call safe to make?
if exefile and os.stat(exefile).st_mode & S_IXUSR != S_IXUSR:
return "%s is not executable" % exefile
return None
def infrastructure_error_multi_paths(path_list):
"""
Similar to infrastructure_error, but accepts a list of paths.
"""
for path in path_list:
if infrastructure_error(path):
return infrastructure_error(path)
return None
|