[PATCH v2 1/2] usertools/devbind: update coding style
Stephen Hemminger
stephen at networkplumber.org
Tue Dec 3 18:07:52 CET 2024
On Tue, 3 Dec 2024 11:25:00 +0000
Anatoly Burakov <anatoly.burakov at intel.com> wrote:
> +
> +def check_installed(program: str, package: str) -> None:
> + """Check if a program is installed."""
> + if subprocess.call(
> + ["which", program], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
> + ):
> + raise DevbindError(f"'{program}' not found - please install '{package}'.")
> +
Apparently the posix way to do this is to use command -v not "which"
command [-pVv] command [arg ...]
Run command with args suppressing the normal shell function
lookup. Only builtin commands or commands found in the PATH are
executed. If the -p option is given, the search for command is
performed using a default value for PATH that is guaranteed to
find all of the standard utilities. If either the -V or -v op‐
tion is supplied, a description of command is printed. The -v
option causes a single word indicating the command or filename
used to invoke command to be displayed; the -V option produces a
more verbose description. If the -V or -v option is supplied,
the exit status is 0 if command was found, and 1 if not. If nei‐
ther option is supplied and an error occurred or command cannot
be found, the exit status is 127. Otherwise, the exit status of
the command builtin is the exit status of command.
More information about the dev
mailing list