Use shutil.which instead of distutils find_executable

The former is the more standard library method for this
with python3
This commit is contained in:
Cole Robinson 2019-06-05 14:15:23 -04:00
parent d2462367ee
commit 2510c299f5
3 changed files with 7 additions and 12 deletions

View File

@ -4,7 +4,6 @@
# See the COPYING file in the top-level directory.
import atexit
from distutils.spawn import find_executable
import io
import logging
import os
@ -29,7 +28,7 @@ os.environ["DISPLAY"] = ":3.4"
TMP_IMAGE_DIR = "/tmp/__virtinst_cli_"
XMLDIR = "tests/cli-test-xml"
OLD_OSINFO = utils.has_old_osinfo()
HAS_ISOINFO = find_executable("isoinfo")
HAS_ISOINFO = shutil.which("isoinfo")
# Images that will be created by virt-install/virt-clone, and removed before
# each run

View File

@ -50,16 +50,13 @@ def _setup_gsettings_path(schemadir):
schema and use it directly
"""
import subprocess
from distutils.spawn import find_executable
import shutil
exe = find_executable("glib-compile-schemas")
exe = shutil.which("glib-compile-schemas")
if not exe:
raise RuntimeError("You must install glib-compile-schemas to run "
"virt-manager from git.")
ret = subprocess.call([exe, "--strict", schemadir])
if ret != 0:
raise RuntimeError("Failed to compile local gsettings schemas")
subprocess.check_call([exe, "--strict", schemadir])
__version__ = "2.1.0"

View File

@ -7,7 +7,6 @@
# See the COPYING file in the top-level directory.
#
from distutils.spawn import find_executable
import logging
import os
import re
@ -143,7 +142,7 @@ def _find_input(input_file, parser, print_cb):
binname = "xz"
pkg = "xz"
cmd = ["tar", "Jxf", input_file, "-C", tempdir]
if not find_executable(binname):
if not shutil.which(binname):
raise RuntimeError(_("%s appears to be an archive, "
"but '%s' is not installed. "
"Please either install '%s', or extract the archive "
@ -252,7 +251,7 @@ class VirtConverter(object):
executable = "/usr/bin/qemu-img"
else:
for binname in binnames:
executable = find_executable(binname)
executable = shutil.which(binname)
if executable:
break
@ -262,7 +261,7 @@ class VirtConverter(object):
base = os.path.basename(absin)
ext = os.path.splitext(base)[1]
if (ext and ext[1:] == "gz"):
if not find_executable("gzip"):
if not shutil.which("gzip"):
raise RuntimeError("'gzip' is needed to decompress the file, "
"but not found.")
decompress_cmd = ["gzip", "-d", absin]