[virt-tools-list] [virt-bootstrap] [PATCH 1/3] utils: Add is_installed function

Daniel P. Berrange berrange at redhat.com
Tue Nov 21 16:31:23 UTC 2017


On Tue, Nov 21, 2017 at 11:37:37AM +0100, Cedric Bosdonnat wrote:
> On Wed, 2017-11-01 at 00:19 +0000, Radostin Stoyanov wrote:
> > Add utility function to check whether an executable is available in
> > the PATH env variable.
> > ---
> >  src/virtBootstrap/utils.py | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
> > index 84d1629..2bd7873 100644
> > --- a/src/virtBootstrap/utils.py
> > +++ b/src/virtBootstrap/utils.py
> > @@ -32,6 +32,7 @@ import subprocess
> >  import sys
> >  import tempfile
> >  import logging
> > +from distutils.spawn import find_executable
> >  
> 
> What annoys me with this approach is that it will add a runtime dependency
> on distutils. as virtBootstrap is not meant to run on a non-linux platform
> couldn't we just call the 'which' tool to do the job?

The 'find_executable' method is pretty trivial. Just split $PATH on
the value of os.pathsep, and then just check each component to see
if it contains the file. Trivial to implement locally without any
fuss, and better than spawning external tools for something so simple


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the virt-tools-list mailing list