acloud: fix py3 compatible issue: ModuleNotFoundError: No module named 'distutils.spawn'

BUG: 137195528
BUG: 144319579
Test: atest acloud_test --host
acloud-dev create
acloud-dev create --local-instance
acloud-dev delete
acloud-dev setup --force

Change-Id: Iced0aef43643c90dfa062a2ef341cf4ab264015c
diff --git a/create/create.py b/create/create.py
index 696cf07..c69b71f 100644
--- a/create/create.py
+++ b/create/create.py
@@ -22,7 +22,6 @@
 
 from __future__ import print_function
 
-from distutils.spawn import find_executable
 import os
 import subprocess
 import sys
@@ -116,7 +115,7 @@
     Args:
         args: Namespace object from argparse.parse_args.
     """
-    if not args.autoconnect or find_executable(constants.ADB_BIN):
+    if not args.autoconnect or utils.FindExecutable(constants.ADB_BIN):
         return
 
     disable_autoconnect = False
diff --git a/delete/delete.py b/delete/delete.py
index 90d3490..562ab62 100644
--- a/delete/delete.py
+++ b/delete/delete.py
@@ -18,7 +18,7 @@
 """
 
 from __future__ import print_function
-from distutils.spawn import find_executable
+
 import logging
 import os
 import re
@@ -69,7 +69,7 @@
                 logger.debug("stop_cvd command: %s", stop_cvd_cmd)
                 return stop_cvd_cmd
 
-    default_stop_cvd = find_executable(constants.CMD_STOP_CVD)
+    default_stop_cvd = utils.FindExecutable(constants.CMD_STOP_CVD)
     if default_stop_cvd:
         return default_stop_cvd
 
diff --git a/internal/lib/adb_tools.py b/internal/lib/adb_tools.py
index 7852a96..434bbd8 100644
--- a/internal/lib/adb_tools.py
+++ b/internal/lib/adb_tools.py
@@ -13,8 +13,6 @@
 # limitations under the License.
 """A tool that help to run adb to check device status."""
 
-from distutils.spawn import find_executable
-
 import re
 import subprocess
 
@@ -91,7 +89,7 @@
         Raises:
             errors.NoExecuteCmd: Can't find the execute adb bin.
         """
-        self._adb_command = find_executable(constants.ADB_BIN)
+        self._adb_command = utils.FindExecutable(constants.ADB_BIN)
         if not self._adb_command:
             raise errors.NoExecuteCmd("Can't find the adb command.")
 
diff --git a/internal/lib/adb_tools_test.py b/internal/lib/adb_tools_test.py
index f546495..cac26d0 100644
--- a/internal/lib/adb_tools_test.py
+++ b/internal/lib/adb_tools_test.py
@@ -20,6 +20,7 @@
 from acloud import errors
 from acloud.internal.lib import adb_tools
 from acloud.internal.lib import driver_test_lib
+from acloud.internal.lib import utils
 
 
 class AdbToolsTest(driver_test_lib.BaseDriverTest):
@@ -151,7 +152,7 @@
         """Test emu command."""
         fake_adb_port = "48451"
         fake_device_serial = "fake_device_serial"
-        self.Patch(adb_tools, "find_executable", return_value="path/adb")
+        self.Patch(utils, "FindExecutable", return_value="path/adb")
         self.Patch(subprocess, "check_output", return_value=self.DEVICE_NONE)
 
         mock_popen_obj = mock.Mock(returncode=1)
diff --git a/internal/lib/ssh.py b/internal/lib/ssh.py
index 590f1de..3ad5042 100755
--- a/internal/lib/ssh.py
+++ b/internal/lib/ssh.py
@@ -18,7 +18,6 @@
 import subprocess
 import threading
 
-from distutils.spawn import find_executable
 from acloud import errors
 from acloud.internal import constants
 from acloud.internal.lib import utils
@@ -204,7 +203,7 @@
         Raises:
             errors.UnknownType: Don't support the execute bin.
         """
-        base_cmd = [find_executable(execute_bin)]
+        base_cmd = [utils.FindExecutable(execute_bin)]
         base_cmd.append(_SSH_CMD % {"rsa_key_file": self._ssh_private_key_path})
         if self._extra_args_ssh_tunnel:
             base_cmd.append(self._extra_args_ssh_tunnel)
diff --git a/internal/lib/utils.py b/internal/lib/utils.py
index 2e74ab5..210fa2a 100755
--- a/internal/lib/utils.py
+++ b/internal/lib/utils.py
@@ -787,7 +787,7 @@
     Raises:
         errors.NoExecuteBin: Can't find the execute bin file.
     """
-    bin_path = find_executable(cmd)
+    bin_path = FindExecutable(cmd)
     if not bin_path:
         raise errors.NoExecuteCmd("unable to locate %s" % cmd)
     command = [bin_path] + args
@@ -922,7 +922,7 @@
                          "Skipping VNC startup.", TextColors.FAIL)
         return
 
-    if not find_executable(_VNC_BIN):
+    if not FindExecutable(_VNC_BIN):
         if no_prompts or GetUserAnswerYes(_CONFIRM_CONTINUE):
             try:
                 PrintColorString("Installing ssvnc vnc client... ", end="")
@@ -943,7 +943,7 @@
         ssvnc_env["SSVNC_SCALE"] = str(scale_ratio)
         logger.debug("SSVNC_SCALE:%s", scale_ratio)
 
-    ssvnc_args = _CMD_START_VNC % {"bin": find_executable(_VNC_BIN),
+    ssvnc_args = _CMD_START_VNC % {"bin": FindExecutable(_VNC_BIN),
                                    "port": port}
     subprocess.Popen(ssvnc_args.split(), env=ssvnc_env)
 
diff --git a/setup.py b/setup.py
index 7305333..0a8eba6 100644
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,10 @@
 
 from __future__ import print_function
 
-from distutils.spawn import find_executable
+try:
+    from distutils.spawn import find_executable
+except ImportError:
+    from shutil import which as find_executable
 import os
 import subprocess
 import sys
@@ -53,8 +56,8 @@
     output = source.replace(".proto", "_pb2.py")
 
     if not os.path.exists(output) or (
-        os.path.exists(source) and os.path.getmtime(source) > os.path.getmtime(output)
-    ):
+            os.path.exists(source) and
+            os.path.getmtime(source) > os.path.getmtime(output)):
         print("Generating %s..." % output)
 
         if not os.path.exists(source):
diff --git a/setup/google_sdk.py b/setup/google_sdk.py
index 925b772..4867ca9 100644
--- a/setup/google_sdk.py
+++ b/setup/google_sdk.py
@@ -27,7 +27,6 @@
 google_sdk.CleanUp()
 """
 
-from distutils.spawn import find_executable
 import logging
 import os
 import platform
@@ -100,7 +99,7 @@
     Return:
         Boolean, return True if gcloud is installed, False otherwise.
     """
-    if find_executable(GCLOUD_BIN):
+    if utils.FindExecutable(GCLOUD_BIN):
         return True
     return False
 
@@ -146,7 +145,7 @@
         Raise:
             NoGoogleSDKDetected if we can't find the sdk path.
         """
-        builtin_gcloud = find_executable(GCLOUD_BIN)
+        builtin_gcloud = utils.FindExecutable(GCLOUD_BIN)
         if builtin_gcloud:
             return os.path.dirname(builtin_gcloud)
         elif os.path.exists(self._tmp_sdk_path):