| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import os |
| 6 from os import path |
| 7 import sys |
| 8 |
| 9 |
| 10 # Based on http://stackoverflow.com/questions/377017/test-if-executable-exists-i
n-python. |
| 11 def which(program): |
| 12 def is_executable(fpath): |
| 13 return path.isfile(fpath) and os.access(fpath, os.X_OK) |
| 14 |
| 15 fpath, fname = path.split(program) |
| 16 if fpath: |
| 17 if is_executable(program): |
| 18 return program |
| 19 return None |
| 20 env_paths = os.environ["PATH"].split(os.pathsep) |
| 21 if sys.platform == "win32": |
| 22 env_paths = get_windows_path(env_paths) |
| 23 for part in env_paths: |
| 24 part = part.strip('\"') |
| 25 file = path.join(part, program) |
| 26 if is_executable(file): |
| 27 return file |
| 28 if sys.platform == "win32" and not file.endswith(".exe"): |
| 29 file_exe = file + ".exe" |
| 30 if is_executable(file_exe): |
| 31 return file_exe |
| 32 return None |
| 33 |
| 34 |
| 35 # Use to find 64-bit programs (e.g. Java) when using 32-bit python in Windows |
| 36 def get_windows_path(env_paths): |
| 37 new_env_paths = env_paths[:] |
| 38 for env_path in env_paths: |
| 39 env_path = env_path.lower() |
| 40 if "system32" in env_path: |
| 41 new_env_paths.append(env_path.replace("system32", "sysnative")) |
| 42 return new_env_paths |
| OLD | NEW |