[libvirt] [jenkins-ci PATCH] lcitool: check for virt-install existing
Pino Toscano
ptoscano at redhat.com
Thu May 2 14:00:28 UTC 2019
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 at redhat.com>
> ---
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190502/c15e2b2b/attachment-0001.sig>
More information about the libvir-list
mailing list