[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Use find_executable() to determine if commands exist



commit 943289dbcb5248e5c703789bb30732986f981135
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Mar 30 19:35:21 2015 -0700

    Use find_executable() to determine if commands exist
    
    Turns out there's no need to crawl through the PATH. Python already has a
    builtin that does exactly what we want.
---
 stem/util/system.py |   13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/stem/util/system.py b/stem/util/system.py
index f2d1bc8..fd62b9d 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -44,6 +44,7 @@ best-effort, providing **None** if the lookup fails.
 
 import ctypes
 import ctypes.util
+import distutils.spawn
 import mimetypes
 import os
 import platform
@@ -194,17 +195,7 @@ def is_available(command, cached=True):
   elif cached and command in CMD_AVAILABLE_CACHE:
     return CMD_AVAILABLE_CACHE[command]
   else:
-    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_exists = distutils.spawn.find_executable(command) is not None
     CMD_AVAILABLE_CACHE[command] = cmd_exists
     return cmd_exists
 

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits