Re: [virt-bootstrap] [PATCH v2 1/3] utils: Add is_installed function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2017-11-21 at 12:08 +0000, Radostin Stoyanov wrote:
> Add utility function to check whether an executable is available in
> the PATH env variable.
> ---
>  src/virtBootstrap/utils.py | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
> index 84d1629..ea84ed3 100644
> --- a/src/virtBootstrap/utils.py
> +++ b/src/virtBootstrap/utils.py
> @@ -646,3 +646,16 @@ def mapping_uid_gid(dest, uid_map, gid_map):
>      balance_uid_gid_maps(uid_map, gid_map)
>      for uid, gid in zip(uid_map, gid_map):
>          map_id(dest, uid, gid)
> +
> +
> +def is_installed(program):
> +    """
> +    Try to find executable listed in the PATH env variable.
> +
> +    Returns the complete filename or None if not found.
> +    """
> +    for path in os.environ["PATH"].split(os.pathsep):
> +        exec_file = os.path.join(path, program)
> +        if os.path.isfile(exec_file) and os.access(exec_file, os.X_OK):
> +            return exec_file
> +    return None

ACK, you can push the whole series ;)

--
Cedric

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list



[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux