[PATCH v2 1/2] usertools/devbind: update coding style

Burakov, Anatoly anatoly.burakov at intel.com
Wed Dec 4 09:59:08 CET 2024


On 12/3/2024 6:07 PM, Stephen Hemminger wrote:
> 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.

Yes but that's for shell, it is not accessible from Python. Well, it 
wouldn't be unless you're suggesting calling into bash and running 
`command -v`?

-- 
Thanks,
Anatoly


More information about the dev mailing list