On Thursday, 2 May 2019 15:44:33 CEST Daniel P. Berrangé wrote: > This improves: > > $ ./lcitool install libvirt-fedora-29 > ./lcitool: Failed to install 'libvirt-fedora-29': [Errno 2] No such file or directory > > To > > $ ./lcitool install libvirt-fedora-29 > ./lcitool: Cannot find virt-install in $PATH > > Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> > --- > guests/lcitool | 23 ++++++++++++++++++++++- > 1 file changed, 22 insertions(+), 1 deletion(-) > > diff --git a/guests/lcitool b/guests/lcitool > index 0f60704..3be16c8 100755 > --- a/guests/lcitool > +++ b/guests/lcitool > @@ -37,6 +37,23 @@ except ImportError: > > class Util: > > + @staticmethod > + def which(program): > + def is_exe(fpath): > + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) > + > + fpath, fname = os.path.split(program) > + if fpath: > + if is_exe(program): > + return program > + else: > + for path in os.environ["PATH"].split(os.pathsep): > + exe_file = os.path.join(path, program) > + if is_exe(exe_file): > + return exe_file > + > + return None There is already shutil.which which does this, although it is only Python 3.3+. As fallback for older versions: - instead of splitting the specified program, I'd just check whether it is an absolute path (os.path.isabs()) - it seems like distutils.spawn.find_executable() can be used for this, which IMHO is better than reimplementing it -- Pino Toscano
Attachment:
signature.asc
Description: This is a digitally signed message part.
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list