summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Johnson <atagar@torproject.org>2018-07-29 13:54:30 -0700
committerDamian Johnson <atagar@torproject.org>2018-07-29 13:54:30 -0700
commit9fa85ec6f751fb060f5dace804dbc3c4c407d77d (patch)
treecb76e187d9a5fbc38faa881d07e58546393bbad7
parente82b3f4317e544e9fce61fc8d93b4cbb72263fd3 (diff)
Drop use of distutils by is_available()
Python3 evidently no longer bundles distutils. We only used it in our utils for simplicity, prior to commit 943289db we manually crawled the path. Effectively reverting commit 943289db. https://trac.torproject.org/projects/tor/ticket/26967
-rw-r--r--stem/util/system.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/stem/util/system.py b/stem/util/system.py
index 94be6b1f..4bfde995 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -67,7 +67,6 @@ best-effort, providing **None** if the lookup fails.
import collections
import ctypes
import ctypes.util
-import distutils.spawn
import itertools
import mimetypes
import multiprocessing
@@ -383,17 +382,26 @@ def is_available(command, cached=True):
command = command.split(' ')[0]
if command in SHELL_COMMANDS:
- # we can't actually look it up, so hope the shell really provides it...
-
- return True
+ return True # we can't actually look it up, so hope the shell really provides it...
elif cached and command in CMD_AVAILABLE_CACHE:
return CMD_AVAILABLE_CACHE[command]
elif 'PATH' not in os.environ:
return False # lacking a path will cause find_executable() to internally fail
- else:
- cmd_exists = distutils.spawn.find_executable(command) is not None
- CMD_AVAILABLE_CACHE[command] = cmd_exists
- return cmd_exists
+
+ cmd_exists = False
+
+ for path in os.environ['PATH'].split(os.pathsep):
+ cmd_path = os.path.join(path, command)
+
+ if is_windows():
+ cmd_path += '.exe'
+
+ if os.path.exists(cmd_path) and os.access(cmd_path, os.X_OK):
+ cmd_exists = True
+ break
+
+ CMD_AVAILABLE_CACHE[command] = cmd_exists
+ return cmd_exists
def is_running(command):