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

View File

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

View File

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